Jump to content

Help needed to find multiple values in a row


Dexlin

Recommended Posts

Hi all,

 

I have the following:

 

class SignupProcess extends DatabaseConnect {
    public function __construct($userid,$email,$password,$mobile)  {
                    if (!@$this->Connect('localhost','root','')) {
                        echo 'Connection Failed';
                    } 
                    else 
                    {
                        mysql_select_db ("es");
                        $query = "SELECT * FROM users WHERE userid='$userid' AND email='$email'AND mobile='$mobile'";
                        $result = mysql_query($query);
                        
                        
                    
                        if (mysql_num_rows($result))
                        {
                                if ( $userid == $userid ) 
                                {
                                echo "User ID " . $userid . " exists!! <br/>";
                                } 
                                 if ( $email == $email ) 
                                {
                                echo "Email " . $email . " exists!! <br/>";
                                } if ( $mobile == $mobile ) 
                                {
                                echo "Mobile " . $mobile . " exists!! <br/>";
                                }
                                
                          }
                          else 
                          {
                                mysql_query("INSERT INTO users (userid, email, password, mobile)
                                VALUES ('$userid','$email','$password','$mobile')");
                                echo "Account created!";
                           }
                      }
    }
}
$c = new SignupProcess('1234','hellol@local.com','123456','00000000000');

 

and when this runs first while db is empty of all records Account created shows Great!, then if i refresh the page it say Userid,Email,Password,Mobile exists Great!, but when i change just the first element being the userid its says Account created!. How do i check if something exists in a row so that userid email password mobile can not be duplicated, as mine works to a certain degree but not totally how i want it to

 

Many thanks

Link to comment
Share on other sites

id should automaticaly generate  mysql

u should make ur `userid` like that

create `sometable` (
`userID`smallint(5) NOT NULL auto_increment,
... some other fields ... ,
PRIMARY KEY  (`userID`) 
)

then when u will run

mysql_query("INSERT INTO users ( email, password, mobile)
                                VALUES ('$email','$password','$mobile')");

id will be 1 , next accaunt will have 2 , then 3 ... 99999

Link to comment
Share on other sites

Sorry, there is a id which is primary and AI, userid is just another field for username. So i have id, userid, email, password, mobile, but i can't work out how to check if userid, email, mobile exists either in the same row or separate then display a message either or all userid, email, mobile exists.

 

Many thanks

Link to comment
Share on other sites

userid ,email and mobile shold be unique in ur base ?

replace "AND" to "OR" in query

$query = "SELECT * FROM users WHERE userid='$userid' OR email='$email' OR mobile='$mobile'";

but if u wont to know wich field already is in base u need to send 3 queries

Link to comment
Share on other sites

I have added:

 

mysql_select_db ("es");
					$query = "SELECT * FROM users WHERE username='$username' OR email='$email' OR mobile='$mobile'";
					$result = mysql_query($query);

					if ($row = mysql_fetch_assoc($result))
					{
						if ( $row['username'] == $username ) { echo " username already exists!! <br/>"; }
						if ( $row['email'] == $email ) { echo "email already exists!! <br/>"; }
						if ( $row['mobile'] == $mobile ) { echo "mobile already exists!! <br/>"; }
					}
					else
					{
						mysql_query("INSERT INTO users (username, email, password, mobile)
						VALUES ('$username','$email','$password','$mobile')");
						echo "Account created!";
				     }

 

and it seems to be working :)

 

Thanks for your help

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.