Jump to content



Photo

Trouble Shooting Php/Mysql


  • Please log in to reply
3 replies to this topic

#1 dorich

dorich

    Newbie

  • Members
  • Pip
  • 5 posts

Posted 6 July 2011 - 5:46 PM

Reference: Chapter 12 "Updating Data In A Database"

Problem: Using the script from the book my version is failing when it comes to submitting the edits.

Description:
I took the script from the book and made small modifications for my own application - the changes were purely things like database name, field names etc.
When the script I typed out failed I took the original downloaded script and merely modified it to suit my application but it still failed.


Symptoms:
The error message is

Could update the entry because: . The query was UPDATE link_problems SET description='Please add as much description as you can about the problem you noticed', url_problem='Destination' WHERE ID=17.


Note that there is no mysql error in the feedback.

Question:
What is the best way to troubleshoot a problem like this where the script fails on the submit. I assume the problem is at my end and that there is something wrong with the either my setup or the minor changes I made to the script but I'm unclear how to troubleshoot.

NOTE: The word "not" is missing in the feedback message in the original script(download version). FYI, although I assume this was corrected in later editions.


Thanks
  • 0

#2 Larry

Larry

    Administrator/Writer

  • Administrators
  • 3,959 posts
  • LocationState College, PA (USA)

Posted 6 July 2011 - 8:29 PM

The standard PHP-MySQL debugging techniques are to print out the query being run, which the code already does, and run that very same query using another interface, such as phpMyAdmin or the mysql client. That way you can directly see the MySQL result.
  • 0

#3 dorich

dorich

    Newbie

  • Members
  • Pip
  • 5 posts

Posted 8 July 2011 - 2:29 PM

The standard PHP-MySQL debugging techniques are to print out the query being run, which the code already does, and run that very same query using another interface, such as phpMyAdmin or the mysql client. That way you can directly see the MySQL result.


Larry:

Thanks that was what I needed.

One thing I noted in debugging is that if I go to the edit entry page, don't make any edits but still click on the submit button I get the same error as reported above:

Could not update the entry because: . The query was UPDATE...............WHERE ID=3.

Since I didn't make any fundamental changes to the script I have to assume that this is the expected behavior. However, I assume that in a production situation this is something to be avoided?
Assuming that this is not a problem I created can you point me to any resources that describe how to overcome this behavior.

Thanks
  • 0

#4 Larry

Larry

    Administrator/Writer

  • Administrators
  • 3,959 posts
  • LocationState College, PA (USA)

Posted 8 July 2011 - 7:58 PM

You're quite welcome. As for what you're experiencing, this is how MySQL behaves: if you run an UPDATE query that works (i.e., executes without error) without actually changing any values, then the number of affected rows is 0. If your PHP scripts just checks the number of affected rows, it'll seem like there was a problem when there wasn't. The alternative is just to check that the query ran without error.
  • 0