ack Posted April 11, 2010 Share Posted April 11, 2010 Is there a way to force a diganostic message from a PHP script to explain why a a MYSQL query has failed? I cannot get past the DIE message when the following code is executed: /* Put the data into the database */ $query= "INSERT INTO buyselltrade (buysell,item,picture,desc,price,contact) VALUES ('$impbuysell','$impitem','$imppicture','$impdesc','$impprice','$impcontact')"; $result = mysql_query($query) or die ("could not save new data!"); I have carefully checked the puncturation against a working version of this script. I have carefully checked the contents of the variables against the table structure. Any ideas? Thanks - Ack Quote Link to comment https://forums.phpfreaks.com/topic/198208-debugging-mysql-query-problems/ Share on other sites More sharing options...
JustLikeIcarus Posted April 12, 2010 Share Posted April 12, 2010 Change your die statement to this: $result = mysql_query($query) or die (mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/198208-debugging-mysql-query-problems/#findComment-1040320 Share on other sites More sharing options...
katierosy Posted April 12, 2010 Share Posted April 12, 2010 mysql_query returns FALSE on error so please check if(!mysql_query($sql)){} Quote Link to comment https://forums.phpfreaks.com/topic/198208-debugging-mysql-query-problems/#findComment-1040391 Share on other sites More sharing options...
ack Posted April 12, 2010 Author Share Posted April 12, 2010 Excellent! I'll give that a try! Thanks, all! Quote Link to comment https://forums.phpfreaks.com/topic/198208-debugging-mysql-query-problems/#findComment-1040499 Share on other sites More sharing options...
ack Posted May 1, 2010 Author Share Posted May 1, 2010 Sorry about the late response on this... I DID get the problem solved! katierosy's post helped isolate things a bit - I'll remember it next time! Here is the "magic concept" that I learned: Be CAREFUL of what you use for variable names! Apparently, one of my variables was the same as a reserved word in either MYSQL or PHP. I changed one of the variable names in the code and everything started to work! Because I have slept a few times since the fix, I cannot report EXACTLY what the variable name was - I only remember that I renamed a variable that was vaguely like something one would find in a computer language reserved name list and things started working. Newbie Debuging Tip: If a Query isn't working and the punctuation is correct, strip all the variables out except for the first one then run the code. Add a variable to the lists one at a time until the code stops working. The variable that you added when it failed is the problem. The problem will be either a reserved word useage error or a naming mismatch somewhere in the code involving that variable. Thanks to all who helped! Quote Link to comment https://forums.phpfreaks.com/topic/198208-debugging-mysql-query-problems/#findComment-1051540 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.