Re: [PHP] Inserting records question
Still learning, so sorry if this sounds really simply noobish. But as I understand things currently this should work. But doesn't. I've been looking over tutorials but just don't see whatever the problem is. I created a simple table with the following fields (in order) tc_id (auto nmbr) lname fname machine_name email_addr problem date_time_submitted (timestamp) And I'm trying to run this insert from form input. $username=somename; $password=somepass; $database=somedb; $table=sometable; mysql_connect(localhost,$username,$password); @mysql_select_db($database) or die(Unable to Connect to DB); $tc_query = INSERT INTO $tablel VALUES(NULL, $lname, $fname, $machine_name, $email_addr, $problem, NULL); $result = mysql_query($tc_query); mysql_close(); So what exactly do I seem to be missing here? As well as what other posters have said (and pay special attention to the suggestions on using mysql_error and single quotes), you are trying to insert a NULL into an autonumber field. You don't need to insert anything here, as the name suggests, it will be populated automatically. You may find it helps you in the future to specify the fields you are inserting. For example, if you add columns to the table, you may see unexpected behaviour. INSERT INTO mytable ( firstname, surname, address, city ) VALUES( 'Guus', 'Hiddink', 'National Stadium', 'Sydney' ) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Inserting records question
Still learning, so sorry if this sounds really simply noobish. But as I understand things currently this should work. But doesn't. I've been looking over tutorials but just don't see whatever the problem is. I created a simple table with the following fields (in order) tc_id (auto nmbr) lname fname machine_name email_addr problem date_time_submitted (timestamp) And I'm trying to run this insert from form input. $username=somename; $password=somepass; $database=somedb; $table=sometable; mysql_connect(localhost,$username,$password); @mysql_select_db($database) or die(Unable to Connect to DB); $tc_query = INSERT INTO $tablel VALUES(NULL, $lname, $fname, $machine_name, $email_addr, $problem, NULL); $result = mysql_query($tc_query); mysql_close(); So what exactly do I seem to be missing here? A lot of single quotes... around the parameters you are inserting... add in a print($tc_query) and see what that looks like... run that directly in mysql and it will give you more details on the error. Or, make it look like this: $tc_query = INSERT INTO $tablel VALUES(NULL, '$lname', '$fname', '$machine_name', '$email_addr', '$problem', NULL); I'd also suggest you read this page: http://www.php.net/mysql_escape_string good luck! -p -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Inserting records question
mysql_connect(localhost,$username,$password); @mysql_select_db($database) or die(Unable to Connect to DB); $tc_query = INSERT INTO $tablel VALUES(NULL, $lname, $fname, $machine_name, $email_addr, $problem, NULL); $result = mysql_query($tc_query); It's always nice to check if the query even ran, using or die(mysql_error()). You might also want to print out the query itself to see if there are missing values. Perhaps you're relying on register globals, which is turned off? $result = mysql_query($tc_query) or die(mysql_error() . in the query $tc_query; -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Inserting records question
It might also be a factor, but the variable containing the table name is $table (not $table1 as coded in the query string). Warren Vail [EMAIL PROTECTED] -Original Message- From: Philip Hallstrom [mailto:[EMAIL PROTECTED] Sent: Thursday, September 08, 2005 6:41 PM To: Iggep Cc: php-general@lists.php.net Subject: Re: [PHP] Inserting records question Still learning, so sorry if this sounds really simply noobish. But as I understand things currently this should work. But doesn't. I've been looking over tutorials but just don't see whatever the problem is. I created a simple table with the following fields (in order) tc_id (auto nmbr) lname fname machine_name email_addr problem date_time_submitted (timestamp) And I'm trying to run this insert from form input. $username=somename; $password=somepass; $database=somedb; $table=sometable; mysql_connect(localhost,$username,$password); @mysql_select_db($database) or die(Unable to Connect to DB); $tc_query = INSERT INTO $tablel VALUES(NULL, $lname, $fname, $machine_name, $email_addr, $problem, NULL); $result = mysql_query($tc_query); mysql_close(); So what exactly do I seem to be missing here? A lot of single quotes... around the parameters you are inserting... add in a print($tc_query) and see what that looks like... run that directly in mysql and it will give you more details on the error. Or, make it look like this: $tc_query = INSERT INTO $tablel VALUES(NULL, '$lname', '$fname', '$machine_name', '$email_addr', '$problem', NULL); I'd also suggest you read this page: http://www.php.net/mysql_escape_string good luck! -p -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php