Re: [PHP] INSERT problem with MySQL/PHP
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 ""; > 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 "\n"; > > -- > Todd A. Jacobs > CodeGnome Consulting, LTD >
Re: [PHP] INSERT problem with MySQL/PHP
On Tue, 19 Jun 2001 08:41, Todd A. Jacobs wrote: > 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 ""; > 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 "\n"; Your INSERT statement is contained in the variable $sql but you are using $sql_query in the mysl_db_query function? -- David Robley Techno-JoaT, Web Maintainer, Mail List Admin, etc CENTRE FOR INJURY STUDIES Flinders University, SOUTH AUSTRALIA URA Redneck if your funeral has more pickup trucks than cars.
Re: [PHP] INSERT problem with MySQL/PHP
Try the following, INSERT INTO questions(user_id,objective,question,question_type) VALUES('$uawr_idx', '$objective', '$question', '$question_type') Define the rows you want to insert into. Hope this helps! Regards, Ray - Original Message - From: "Todd A. Jacobs" <[EMAIL PROTECTED]> To: "PHP General" <[EMAIL PROTECTED]> 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 ""; > 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 "\n"; > > -- > Todd A. Jacobs > CodeGnome Consulting, LTD
Re: [PHP] INSERT problem with MySQL/PHP
Todd, Did you echo $sql and examine it? Did you try the statement at the mysql console? Does the list of values exactly match the field list? Did you try the alternate syntax INSERT [LOW_PRIORITY | DELAYED] [IGNORE] [INTO] tbl_name SET col_name=expression, col_name=expression, ... as in the MySQL docs? I'm really curious about what $sql looks like when you echo it. I've been surprised more than once. Miles Thompson At 04:11 PM 6/18/01 -0700, Todd A. Jacobs wrote: >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 ""; > 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 "\n"; > >-- >Todd A. Jacobs >CodeGnome Consulting, LTD
Re: [PHP] INSERT problem with MySQL/PHP
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" <[EMAIL PROTECTED]> To: "PHP General" <[EMAIL PROTECTED]> 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 ""; > 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 "\n"; > > -- > Todd A. Jacobs > CodeGnome Consulting, LTD >
Re: [PHP] INSERT problem with MySQL/PHP
On Mon, 18 Jun 2001, Todd A. Jacobs wrote: > $sql = "INSERT INTO question VALUES (NULL, $user_idx, $objective, > '$question', '$question_type', NULL, NULL)"; > > $result = mysql_db_query('item_db', $sql_query, $connection_id); Thanks to all who answered. It was a simple mistake, but hard for the eye to catch: I needed the query to use $sql, not $sql_query. The program now works properly. Thank you. -- Todd A. Jacobs CodeGnome Consulting, LTD
RE: [PHP] INSERT problem with MySQL/PHP
> 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); ^^ I daresay this will be the problem since the SQL is in $sql. Jason