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); } ?> Link to comment https://forums.phpfreaks.com/topic/145375-solved-mysql-dump-and-die/ 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? Link to comment https://forums.phpfreaks.com/topic/145375-solved-mysql-dump-and-die/#findComment-763179 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 Link to comment https://forums.phpfreaks.com/topic/145375-solved-mysql-dump-and-die/#findComment-763180 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? Link to comment https://forums.phpfreaks.com/topic/145375-solved-mysql-dump-and-die/#findComment-763181 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. Link to comment https://forums.phpfreaks.com/topic/145375-solved-mysql-dump-and-die/#findComment-763183 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. Link to comment https://forums.phpfreaks.com/topic/145375-solved-mysql-dump-and-die/#findComment-763184 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. Link to comment https://forums.phpfreaks.com/topic/145375-solved-mysql-dump-and-die/#findComment-763186 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)); } ?> Link to comment https://forums.phpfreaks.com/topic/145375-solved-mysql-dump-and-die/#findComment-763188 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. Link to comment https://forums.phpfreaks.com/topic/145375-solved-mysql-dump-and-die/#findComment-763191 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? Link to comment https://forums.phpfreaks.com/topic/145375-solved-mysql-dump-and-die/#findComment-763193 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 Link to comment https://forums.phpfreaks.com/topic/145375-solved-mysql-dump-and-die/#findComment-763196 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. Link to comment https://forums.phpfreaks.com/topic/145375-solved-mysql-dump-and-die/#findComment-763327 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. Link to comment https://forums.phpfreaks.com/topic/145375-solved-mysql-dump-and-die/#findComment-763328 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 Link to comment https://forums.phpfreaks.com/topic/145375-solved-mysql-dump-and-die/#findComment-763976 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. Link to comment https://forums.phpfreaks.com/topic/145375-solved-mysql-dump-and-die/#findComment-763987 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.