Jump to content

PHP database returning customization


plznty

Recommended Posts

Yeah, but then there could actually an sql error; so the user would be told their username is taken no matter what they put.

 

On my site I just run a query to select anyone with the chosen username. If 0 rows are returned; proceed...

Link to comment
Share on other sites

The most direct solution is to execute the INSERT query, test if it failed or worked, and if it failed with a mysql_errno() value of 1062 (which corresponds to the Duplicate entry xxx for key yyy error), output the custom error message. This only requires some simple conditional logic to be added to test the mysql_errno() in the existing error checking logic that should already be present (everyone already has basic error checking logic if(){}else{} in their application on their queries, right?)

 

The second best way (requires two queries and more php logic) would be to execute a SELECT query to test if the username has already been taken, perform the logic to test how many rows were matched, output the custom error message if there is already a row, then execute the INSERT query if there is not.

Link to comment
Share on other sites

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.