Jump to content

Recommended Posts

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

 

Link to comment
https://forums.phpfreaks.com/topic/198208-debugging-mysql-query-problems/
Share on other sites

  • 3 weeks later...

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!   

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.