Jump to content

[SOLVED] PHP - SQL Query Help


tsilenzio

Recommended Posts

Ok I know how to do php with no problem (mostly) or atleast so far. However if i have a table in a database set up called: users and the columns are: UserID [Auto Increased], Email, Username, TimeStamp, and Status.

 

How would I write a query to first make sure that the user who is in the process of registering isnt entering an email hasn't been used yet and also check to make sure that the loginname isnt already used?

 

And then later when they check their email they click the activation link (already coded so im not worried about that) but how would I change the Status field from 0 to 1? - [THIS BEING A COMPLETLY DIFF QUERY THEN THE OTHER]

 

Sorry this whole query thing is confusing but if i can see how its written a few times with the examples id need then it would help me out a great deal!

 

Thanks ALOT!

Link to comment
Share on other sites

$result = mysql_query("SELECT userid FROM users WHERE (email = 'email@addy.com' OR username = 'username')");

if (mysql_num_rows($result) > 0) {
    echo 'The username/email is already in use.';
}

 

If you want to be able to display a helpful error message you need to branch that off into 2 queries instead of just one so the user knows that it was the username  that was invalid etc.

Link to comment
Share on other sites

like $result = 1 if it went sucessful or $result = 0 if unsecessful?  :-\

 

$result is neither. It is a mysql resource. Even if the query returns 0 rows, it is still a valid query. That is why you have to use mysql_num_rows to check.

 

www.php.net/mysql_query

 

Returns a MySQL Resource ID. Which is used by mysql_fetch_array etc to retrieve the data.

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.