Michan Posted October 25, 2007 Share Posted October 25, 2007 Hi everyone, The following code is driving me crazy; $desc = ('test'); mysql_query('INSERT INTO vg_features (category, game, priority, limage, simage, link, title, type, desc) VALUES ("'.$cats.'", "'.$games.'", "'.$_POST['priority'].'", "'.$file.'", "'.$file2.'", "'.$link.'", "'.$_POST['featuretitle'].'", "'.$type.'", "'.$desc.'")'); It all works (tested), sans the "desc" and ""'.$desc.'"." I've tested it a gajillion times and tried changing $desc to a multitude of things, as well as replaced "'.$desc.'" with "test", but for some reason, only that "desc" part is not inserting into the database. Here is the corresponding mysql structure for that area of the table: link longtext latin1_swedish_ci title text latin1_swedish_ci desc text latin1_swedish_ci It is ABSOLUTELY the "desc" part that isn't working, as it works fine without it. Please, somebody help me here! Quote Link to comment https://forums.phpfreaks.com/topic/74688-solved-this-code-is-driving-me-insane-cant-figure-out-bug/ Share on other sites More sharing options...
teng84 Posted October 25, 2007 Share Posted October 25, 2007 $query ='INSERT INTO vg_features (category, game, priority, limage, simage, link, title, type, desc) VALUES ("'.$cats.'", "'.$games.'", "'.$_POST['priority'].'", "'.$file.'", "'.$file2.'", "'.$link.'", "'.$_POST['featuretitle'].'", "'.$type.'", "'.$desc.'")'; echo $query; mysql_query($query ) or die (mysql_error()); try and tell us what happen Quote Link to comment https://forums.phpfreaks.com/topic/74688-solved-this-code-is-driving-me-insane-cant-figure-out-bug/#findComment-377590 Share on other sites More sharing options...
trq Posted October 25, 2007 Share Posted October 25, 2007 desc is a reserved word in sql. You need to escape reserved words using `backticks`. Also, you should always check your queries for success. Try... <?php $sql = "INSERT INTO vg_features ( category, game, priority, limage, simage, link, title, type, `desc` ) VALUES ( '$cats', '$games', '{$_POST['priority']}', '$file', '$file2', '$link', '{$_POST['featuretitle']}', '$type', '$desc' );"; if (mysql_query($sql)) { echo "insert success!"; } else { echo mysql_error() . "<br />$sql"; } ?> You really ought to be checking the data from $_POST prior to insert aswell. Quote Link to comment https://forums.phpfreaks.com/topic/74688-solved-this-code-is-driving-me-insane-cant-figure-out-bug/#findComment-377591 Share on other sites More sharing options...
hostfreak Posted October 25, 2007 Share Posted October 25, 2007 Thorpe, can you link me to the MySQL documentation on the backtick? I've been meaning to look into it, but the MySQL manual never seems easy to navigate. Quote Link to comment https://forums.phpfreaks.com/topic/74688-solved-this-code-is-driving-me-insane-cant-figure-out-bug/#findComment-377593 Share on other sites More sharing options...
trq Posted October 25, 2007 Share Posted October 25, 2007 Sorry, Ive no idea where that is. There is a page of reserved words here though. Quote Link to comment https://forums.phpfreaks.com/topic/74688-solved-this-code-is-driving-me-insane-cant-figure-out-bug/#findComment-377596 Share on other sites More sharing options...
Michan Posted October 25, 2007 Author Share Posted October 25, 2007 Thank you very much. I feel so stupid for pondering over this for hours :-X It works perfectly now, though! Quote Link to comment https://forums.phpfreaks.com/topic/74688-solved-this-code-is-driving-me-insane-cant-figure-out-bug/#findComment-377599 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.