I just thought I would re-iterate something that I have mentioned a few times in my replies to threads on here in that if your code isn't working, one of the first things to do is actually test your query in the database (i.e. through phpMyAdmin).

The reason I am posting this is that even though I have advised people quite a few times to do this, I had a problem the other day with some very simple coding and very basic update query and I just couldn't work out what the problem was - there was no logical reasoning for it not to work.

Eventually I decided to test the query in phpMyAdmin and guess what, I got an error and I resolved the problem - just a silly missing comma between the 2 fields and values I wanted to update.

The moral of the story: Firstly I should follow my own advice:) and secondly please test your queries in the database - it can save you a lot of time, head scratching and save your sanity.

pritaeas commented: Agree, although it won't happen... +14

Recommended Answers

All 5 Replies

Wow. I never thought that we actually can test our queries in the Database like phpMyAdmin. Thanks for the advice, buddy. Will you please enlighten us on how you'd use the DB to test queries or what part of the DB you use to do that?

I know that missing a comma or apostrophe or anything in queries would waste heaps and heaps of one's time just to debug and see what the problem is.

OK, an example, you have a table called customers and each customer has an id and you want to select all the details for the customer with an id of 1 (this is so simple it should work so it is not a query that will fail, just adjust to match your table and column name(s)).

Login to phpMyAdmin, select the correct database on the left menu and then click the SQL tab towards the top of the page then type or copy in your query, in this case

SELECT * FROM customers WHERE id=1

When you have an error your want to check just copy and paste your query into the SQL form (as above) replacing the $ variables with actual data.

It is the same as using or die(mysql_error()) at the end of your queries in your PHP but just done within the database itself so can sometimes be a bit quicker and easier for testing/debugging.

Yes of course.I'm also agree with your opinion.And other thing is,simply we can generate a PHP code for the relevant SQL query via the phpMyAdmin.That's a nice option of that.It reduces the errors when we write the code in PHP..:)

Exactly:)

I should give that a go. Thanks for sharing this piece of information with us, buddy.

We sometimes learn from others .

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.