Only a small little problem.. you called your sql query $sql and then in
your mysql_db_query line called it $sql_query..call them both the same name
and it should work!

HTH,Tom
----- Original Message -----
From: "Todd A. Jacobs" <[EMAIL PROTECTED]>
To: "PHP General" <[EMAIL PROTECTED]>
Sent: Tuesday, June 19, 2001 12:11 AM
Subject: [PHP] INSERT problem with MySQL/PHP


> PHP: 4.0.4pl1
> MySQL: 3.23.36-1
>
> I have the following code fragment, which uses the same connection
> parameters elsewhere to *successfully* to retrieve data from a database,
> so this doesn't appear to be a permissions problem with MySQL.
>
> However, nothing happens with inserts; no rows are added at all. All I get
> is a message form mysql_error() saying "Query was empty."
>
> Can anyone tell me what might be wrong?
>
>     $user_idx  = 1;
>     $objective = 1;
>     $question  = 'Foo';
>     $question_type = 'singular';
>
>     $connection_id = mysql_connect ('192.168.1.1', 'php', 'password')
> or die ("No connection.\n");
>
>     $sql = "INSERT INTO question VALUES (NULL, $user_idx, $objective,
> '$question', '$question_type', NULL, NULL)";
>
>     $result = mysql_db_query('item_db', $sql_query, $connection_id);
>
>     echo "<pre>";
>     echo "\nDebugging output:\n";
>     echo "\tSQL: $sql\n";
>     echo "\tError: ", mysql_error(), "\n";
>     echo "\tLast insert ID: ", mysql_insert_id(), "\n";
>     echo "\tResult: $result\n";
>     echo "</pre>\n";
>
> --
> Todd A. Jacobs
> CodeGnome Consulting, LTD
>

Reply via email to