elseif(check_email($email) == true) { $checkuser = mysql_query("SELECT * FROM `memebers` WHERE `username` = '$user'"); $checkemail = mysql_query("SELECT * FROM `memebers` WHERE `email` = '$email'"); if(mysql_num_rows($checkemail) > 0 ) { return "emailexists"; }elseif(mysql_num_rows($checkuser) == 0 ) { $sql = "INSERT INTO `$db`.`memebers` (`id`, `username`, `password`, `email`, `style`, `ip`) VALUES ('', '$user', '$pass', '$email', 'style.css','$ip');"; mysql_query($sql); return "success"; My database won't check for amount of rows. I also set up a basic query and tried to print it, it never returns the data, I don't know whats going wrong, maybe its my sql connection? Let me know if you need any further information, this is a example of the code It inserts just fine, but it wont even find rows even if it exsist, I noticed it didnt work when i started trying to create a login system and it wont the usernames and passwords
The syntax for mysql_num_rows() looks okay in regards to how it's used. If it's inserting, that means that mysql_num_rows($checkuser) is less than 0. In the if/elseif statement, it checks to see if the first statement is true. If it is, it skips the rest of the if statement. If it's false, it continues on in a procedural pattern. So if the record is being inserted, that means (as stated above) that the "Email exists" bit isn't returning with an integer higher than 0. I'd recommend testing out code similar to: elseif(check_email($email) == true) { $checkuser = mysql_query("SELECT * FROM `memebers` WHERE `username` = '$user'"); $checkemail = mysql_query("SELECT * FROM `memebers` WHERE `email` = '$email'"); echo 'Email: '.$email; echo 'User: '.$user; echo mysql_num_rows($checkemail); if(mysql_num_rows($checkemail) > 0 ) { return "emailexists"; } elseif(mysql_num_rows($checkuser) == 0 ) { $sql = "INSERT INTO `$db`.`memebers` (`id`, `username`, `password`, `email`, `style`, `ip`) VALUES ('', '$user', '$pass', '$email', 'style.css','$ip');"; mysql_query($sql); return "success"; PHP:
Still doesn't work I would also like to point out even this wont find the row i added to database function login($username,$password){ mysql_select_db($database_database, $sql_connect); $result = mysql_query("SELECT `id` FROM `memebers` WHERE `username` = 'domdadank' AND `password` = '1234567'", $sql_connect); $num_rows = mysql_num_rows($result); if($num_rows > 0) {return true;}else{return false;} } Ignore the function for now, I just made a static entry for the SELECT and it wont get it. It will work inside of phpmyadmin though. I made a new username for database with all privileges like my other and that didn't work either
Hmm.. Things to check: Are you connected to the proper MySQL Database? Does this work when ran in PhpMyAdmin? SELECT `id` FROM `memebers` WHERE `username` = 'domdadank' AND `password`= '1234567' LIMIT 1; Code (markup): Also check to see if the $email/$user variables have the proper data in them when the query is made.
id 7 IT returns the ID properly. Im willing to talk on skype or MSN if anyone would like to connect to files and take a heavy look, I just dont want them posted all over.
$result = mysql_query("SELECT `id` FROM `memebers` WHERE `username` = 'domdadank' AND `password` = '1234567'") or die(mysql_error()); PHP: and mysql_select_db($database_database, $sql_connect) or die(mysql_error()); PHP: