Q695 Posted February 16, 2009 Share Posted February 16, 2009 The site I'm using to load data into a database was working fine, now it's dumping data to the browser and dieing, and I don't know why. <?php if ($catagory && $column_name){ $sql="INSERT INTO categories ( `name` , `type` , `column_name` , 'image', 'text' ) VALUES ( '$catagory', '0', '$column_name', '$image', '$text');"; $result=@mysql_query($sql,$con) or die($sql); } ?> Quote Link to comment Share on other sites More sharing options...
genericnumber1 Posted February 16, 2009 Share Posted February 16, 2009 Try removing the @ and changing die($sql) to die(mysql_error())... what do you mean it's "dumping data"? what data is it dumping? Quote Link to comment Share on other sites More sharing options...
Q695 Posted February 16, 2009 Author Share Posted February 16, 2009 death does both the mysql error, and the sql statement, so I like it better It dumps $sql You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''image', 'text' ) VALUES ( 'Electrical', '0', 'Electrical', 'http://www.qualityc' at line 5 Quote Link to comment Share on other sites More sharing options...
genericnumber1 Posted February 16, 2009 Share Posted February 16, 2009 Show us the "there's an error in your syntax" error message? Quote Link to comment Share on other sites More sharing options...
Mchl Posted February 16, 2009 Share Posted February 16, 2009 Is this all of your script? Where does the data for this script come from? Check if the variables used in the query are not empty. Quote Link to comment Share on other sites More sharing options...
Q695 Posted February 16, 2009 Author Share Posted February 16, 2009 It checks to see which form was submitted, then runs the code for that form. Quote Link to comment Share on other sites More sharing options...
Q695 Posted February 16, 2009 Author Share Posted February 16, 2009 That is a script within my requirements loader document. Quote Link to comment Share on other sites More sharing options...
Q695 Posted February 16, 2009 Author Share Posted February 16, 2009 The whole script is: <?php $catagory=$_POST[catagory]; $column_name=$_POST[column_name]; $image=$_POST[image]; $text=$_POST[text]; if ($catagory && $column_name && $image && $text){ $sql="INSERT INTO categories ( `name` , `type` , `column_name` , 'image', 'text' ) VALUES ( '$catagory', '0', '$column_name', '$image', '$text');"; $result=@mysql_query($sql,$con) or die(death($sql)); } ?> Quote Link to comment Share on other sites More sharing options...
haku Posted February 16, 2009 Share Posted February 16, 2009 You have the wrong type of single quotes around image and text. Switch them to be the same as the rest of your quotes. Quote Link to comment Share on other sites More sharing options...
Q695 Posted February 16, 2009 Author Share Posted February 16, 2009 Thank you Haku, why is PHP/MySQL so particular about quotes being used? Quote Link to comment Share on other sites More sharing options...
Mchl Posted February 16, 2009 Share Posted February 16, 2009 `something` <- a database object (a table, a column etc.) 'something' <- a literal string Quote Link to comment Share on other sites More sharing options...
haku Posted February 16, 2009 Share Posted February 16, 2009 To some degree it's not picky at all. You don't need the quotes around column names. Actually you don't need them around values either, though for security purposes, it's better to put them around values. But you can leave them off of the column names with no worries. Quote Link to comment Share on other sites More sharing options...
Mchl Posted February 16, 2009 Share Posted February 16, 2009 Actually you don't need them around values either, You DO need them around _string_ values. Otherwise MySQL will think you want to insert value from another column. Quote Link to comment Share on other sites More sharing options...
Q695 Posted February 17, 2009 Author Share Posted February 17, 2009 Interesting, I've always copied the code from phpMyAdmin Quote Link to comment Share on other sites More sharing options...
haku Posted February 17, 2009 Share Posted February 17, 2009 Ahh ya, of course. I wasn't thinking Actually you don't need them around values either, You DO need them around _string_ values. Otherwise MySQL will think you want to insert value from another column. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.