Benjamin: SQL Befehl der in phpmyadmin läuft aber nicht in phpscript

for($i =0; $i<sizeof($tmp);$i++) {
    q = $q."INSERT INTO interest_answer (user_id, question, answer)
    VALUES (".$db->quote($user_id).", ".$db->quote($question).",
            ".$db->quote($tmp[$i+1]).");
    ";
}

$affectedRows = $db->exec($q);
if (PEAR::isError($affectedRows)) {
   die($affectedRows->getMessage());

}

in $tmp steht
Array
(
    [1] => 10 Frauen(18-20)
    [2] => WindKraftwerk
    [3] => Highend Rechner
    [4] => DSL16000+
    [5] => Ein Boot! :)
)
$user_id und $question sind zahlen (1-99999)

Was ich will ist in eine sql datenbank 1-5 zeilen reinschreiben...

$q sind bis zu 5 sql-befehle hintereinander immer durch ein ; getrennt (so wie man das in phpmyadmin auch machen kann)
aber ich bekomm in phpscript immer einen syntaxfehler...wenn ich echo $q; mache und den ganzen string in phpmyadmin reinkopiere funktioniert es ohne probleme ...warum ?

oder wie muss mein sql string aussehen damit ich z.B 3 zeilen aufeinmal hinzufüge?
------------------------------
| user_id | questin | answer |

|    5    |    1    |  text1 |
|-----------------------------
|    5    |    1    |  text2 |
------------------------------
|    5    |    1    |  text3 |
------------------------------

  1. for($i =0; $i<sizeof($tmp);$i++) {
        q = $q."INSERT INTO interest_answer (user_id, question, answer)
        VALUES (".$db->quote($user_id).", ".$db->quote($question).",
                ".$db->quote($tmp[$i+1]).");
        ";
    }

    Du muss quotation-marks um deine values machen wenn's strings sind.

    for($i =0; $i<sizeof($tmp);$i++) {
        q = $q."INSERT INTO interest_answer (user_id, question, answer)
        VALUES (".$db->quote($user_id).", '".$db->quote($question)."',
                '".$db->quote($tmp[$i+1])."');
        ";
    }

    1. dann hätte ich ''string'' als anwort ... :)
      um da net zu beachten hab ich $db->quote geschrieben ;)

  2. Hello,

    $q sind bis zu 5 sql-befehle hintereinander immer durch ein ; getrennt (so wie man das in phpmyadmin auch machen kann)

    das machen die Standartbefehle für mysql unter PHP nicht mit (Sicherheitsgründe, siehe SQL-Injection). PHPMyAdmin verheimlicht das vor dir in dem es deine Eingabe automatisch auf diese Trenner parst und die Befehle getrennt voneinander absetzt.

    MfG
    Rouven

    --
    -------------------
    He is entertaining both out of the car and in the car because if you tell him that a corner is almost flat then he is the guy who is going to try to take it flat even if it means shunting it the other side of it, he will come with the data and say 'hey, I may have crashed and destroyed the car, but I was flat-out'. That is an interesting quality that he has!  --  Team Member on Jacques Villeneuve
    1. Servus,

      das machen die Standartbefehle für mysql unter PHP nicht mit

      Könnte es klappen, wenn man sie zu einer bestimmten Sitzart auffordert? Vielleicht wollens die ja gemütlicher...

      Gruss
      Patrick

      --
      sh:( fo:| ch:? rl:( br:> n4:( ie:% mo:) va:} de:> zu:) fl:| ss:| ls:[ js:|
      1. Hello,

        das machen die Standartbefehle für mysql unter PHP nicht mit
        Könnte es klappen, wenn man sie zu einer bestimmten Sitzart auffordert? Vielleicht wollens die ja gemütlicher...

        dope, von Zeit zu Zeit schleicht sich das doch immer mal wieder ein *in die Ecke stell und schäm*

        MfG
        Rouven

        --
        -------------------
        He is entertaining both out of the car and in the car because if you tell him that a corner is almost flat then he is the guy who is going to try to take it flat even if it means shunting it the other side of it, he will come with the data and say 'hey, I may have crashed and destroyed the car, but I was flat-out'. That is an interesting quality that he has!  --  Team Member on Jacques Villeneuve