inulled Posted October 1, 2011 Share Posted October 1, 2011 <?php session_start(); include("global-settings.php"); mysql_connect($dbhost, $dbuser, $dbpass)or die("Could Not Connect: " . mysql_error()); mysql_select_db($dbname) or die(mysql_error()); $email = mysql_real_escape_string(strip_tags($_POST["email"])); $password = sha1($_POST["password"]); $result = mysql_query("SELECT * FROM users WHERE username = '{$email}' AND password = '{$password}'"); if (mysql_num_rows($result) > 0) { $row = mysql_fetch_array($result); $_SESSION["userid"] = $row['user_pid']; echo "logged in"; } else { $userid_generator = uniqid(rand(), false); mysql_query("INSERT INTO users (user_pid, email, password, datetime_registered, is_leader) VALUES ('$userid_generator', '{$email}', '{$password}', NOW(), 'no')"); $id = mysql_insert_id(); $leaders = mysql_query("SELECT * FROM users WHERE is_leader LIKE '%yes%'"); while($rows = mysql_fetch_array($leaders)) { if ($rows['is_leader'] == 'yes') { $leader_id = $rows['user_pid']; mysql_query("INSERT IGNORE INTO friends (node1id, node2id, friends_since, friend_type) VALUES('$leader_id', '$userid_generator', NOW(), 'full')"); $_SESSION["userid"] = $userid_generator; echo '[DEBUG] $row[\'email\']' . $email . "<br>"; echo '[DEBUG] $row[\'password\']' . $password . "<br>"; echo "new user created and logged in"; if(is_dir($userid_generator)) { echo "Something wen't wrong. A bug report has been sent and we are doing what we can to fix it."; $message = 'Registration problem on account number $userid_generator. The user succesfully registered, but there is already a directory with the account id of $userid_generator.'; mail($bug_report_email, "Registration Bug!", $message); } else { mkdir('../media/User-PID{' . $userid_generator . '}', 0777); mkdir('../media/User-PID{' . $userid_generator . '}/photos', 0777); mkdir('../media/User-PID{' . $userid_generator . '}/backups', 0777); mkdir('../media/User-PID{' . $userid_generator . '}/videos', 0777); mkdir('../media/User-PID{' . $userid_generator . '}/documents', 0777); mkdir('../media/User-PID{' . $userid_generator . '}/developer', 0777); mkdir('../media/User-PID{' . $userid_generator . '}/developer/apps', 0777); mkdir('../media/User-PID{' . $userid_generator . '}/developer/themes', 0777); mkdir('../media/User-PID{' . $userid_generator . '}/xml', 0777); } } } } ?> Why am I getting the following error message: Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\Local Network\htdocs\processing\register.inc.php on line 11 Also I can't seem to get the else statement to execute if the if... statement returns false. Any ideas as to what the problem may be? Quote Link to comment https://forums.phpfreaks.com/topic/248236-screwy-code-logic/ Share on other sites More sharing options...
xyph Posted October 1, 2011 Share Posted October 1, 2011 $result = FALSE. I wonder how that could happen? Perhaps a visit to the manual would help explain. Quote Link to comment https://forums.phpfreaks.com/topic/248236-screwy-code-logic/#findComment-1274763 Share on other sites More sharing options...
ignace Posted October 1, 2011 Share Posted October 1, 2011 $sql = "SELECT * FROM users WHERE username = '{$email}' AND password = '{$password}'"; $result = mysql_query($sql) or exit("ERROR: " . mysql_error() . "<br>IN QUERY: " . $sql); Gives you a description of what's wrong with your query. It's advisable not to use or exit() in production environments. Quote Link to comment https://forums.phpfreaks.com/topic/248236-screwy-code-logic/#findComment-1274773 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.