Ask the Expert

PHP page works sometimes, not others

Weird problem. I have a form on a PHP page that collects three fields. When submit is selected, the data is sent to a second page where MySQL writes the data. But sometimes it works, and sometimes it doesn't. For new users who have not been entered into the database, sometimes it writes data successfully and other times it just gives me a 0 and no data is written. Any ideas what I should be looking at? I have six other databases running in the same environment that have never had this type of problem.

Requires Free Membership to View

Well the first thing to do would be to look at the output of the mysql_error() function in PHP. This function will provide the textual error message from the MySQL server, which may shed some light on the problem. Another recommendation is to send this error message, along with any relevant information, to yourself with the mail() PHP function when an error is encountered. This may help identify trends.

One area to watch for is users violating primary keys or UNIQUE indexes. Before inserting the row, check and make sure the row is truly unique, or catch the error and ask the user for new information.

This was first published in November 2004

There are Comments. Add yours.

TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to: