DamienRoche Posted July 28, 2008 Share Posted July 28, 2008 Last question, I won't spam the board. I am having a lot of trouble inserting data in my MYSQL db. Here's my problem: $mysql_query = "INSERT INTO $table (id, First Name, Surname, Position, Phone Number, Email Address, Company/Organization, Reg/VAT Number, Address Line 1, Address Line 2, Address Line 3, City, Country, Post/Zip Code, Qualifying from Where) VALUES('$unique_id','$fname','$sname','$pos','$pnum','$email','$compname','$regno','$adline1','$adline2',$adline3','$city','$country','$postzip','$qualwho')" or die("unable to insert data into $table"); None of the data is submitted. Yet, I can easily submit data using the code below: $mysql_query = "INSERT INTO $table (id, fname, sname) VALUES('$unique_id','$fname','$sname')" or die("unable to insert data into $table"); I have added the relevant fields to the table, there is absolutely no typos. I'm not getting any error messages and the data is definitely being transferred from the form because I've had it splashed out using the same php file. Does anyone have any idea what is going wrong or what i can do to troubleshoot? Thanks, Damien. Link to comment https://forums.phpfreaks.com/topic/116964-problem-inserting-data-into-mysql-db/ Share on other sites More sharing options...
JasonLewis Posted July 28, 2008 Share Posted July 28, 2008 change your die() to this: die("Unable to insert data into {$table}. MySQL said: ".mysql_error()); I would also wrap all column names in ` Like so: `First Name` Link to comment https://forums.phpfreaks.com/topic/116964-problem-inserting-data-into-mysql-db/#findComment-601521 Share on other sites More sharing options...
samshel Posted July 28, 2008 Share Posted July 28, 2008 i think you have confused variable name with function name...you are not calling the function mysql_query anywhere , how will it insert? try this... $mysql_query = mysql_query("INSERT INTO $table (id, fname, sname) VALUES('$unique_id','$fname','$sname')") or die("unable to insert data into $table"); Link to comment https://forums.phpfreaks.com/topic/116964-problem-inserting-data-into-mysql-db/#findComment-601523 Share on other sites More sharing options...
DamienRoche Posted July 28, 2008 Author Share Posted July 28, 2008 Hey thanks a lot! It helped me get closer to the broken cogs. Here's what MYSQL says: check the manual that corresponds to your MySQL server version for the right syntax to use near 'Name, Surname, Position, Phone Number, Email Address, Company/Organization, Reg/' at line 1 Any insights? Thanks for the help. Link to comment https://forums.phpfreaks.com/topic/116964-problem-inserting-data-into-mysql-db/#findComment-601526 Share on other sites More sharing options...
DamienRoche Posted July 28, 2008 Author Share Posted July 28, 2008 Second time I've done this...sussed it out, thanks to the handy tips above. Turns out I'm not allowed to use spaces or other special characters in the field names. Thanks for all your help guys! Link to comment https://forums.phpfreaks.com/topic/116964-problem-inserting-data-into-mysql-db/#findComment-601531 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.