Jump to content

Screwy Code Logic


inulled

Recommended Posts

<?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?

Link to comment
Share on other sites

$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.

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.