Dexlin Posted June 28, 2012 Share Posted June 28, 2012 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','[email protected]','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 https://forums.phpfreaks.com/topic/264929-help-needed-to-find-multiple-values-in-a-row/ Share on other sites More sharing options...
memfiss Posted June 28, 2012 Share Posted June 28, 2012 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 https://forums.phpfreaks.com/topic/264929-help-needed-to-find-multiple-values-in-a-row/#findComment-1357681 Share on other sites More sharing options...
Dexlin Posted June 28, 2012 Author Share Posted June 28, 2012 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 https://forums.phpfreaks.com/topic/264929-help-needed-to-find-multiple-values-in-a-row/#findComment-1357685 Share on other sites More sharing options...
memfiss Posted June 28, 2012 Share Posted June 28, 2012 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 https://forums.phpfreaks.com/topic/264929-help-needed-to-find-multiple-values-in-a-row/#findComment-1357695 Share on other sites More sharing options...
Dexlin Posted June 28, 2012 Author Share Posted June 28, 2012 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 https://forums.phpfreaks.com/topic/264929-help-needed-to-find-multiple-values-in-a-row/#findComment-1357713 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.