Re: INSERT problem with MySQL/PHP

From: Date: Tue, 19 Jun 2001 03:17:53 +0000
Subject: Re: INSERT problem with MySQL/PHP
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-54308@lists.php.net to get a copy of this message
replace $result = mysql_db_query('item_db', $sql_query, $connection_id); with $result = mysql_db_query('item_db', $sql, $connection_id); or just mysql_query($sql); ----- Original Message ----- From: "Todd A. Jacobs" <nospam@codegnome.org> To: "PHP General" <php-general@lists.php.net> Sent: Monday, June 18, 2001 4:11 PM 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 >

« previous php.general (#54308) next »