<?php
include("global-settings.php");
session_start();
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 = mysql_real_escape_string(strip_tags(sha1($_POST['password'])));
$result = mysql_query("SELECT * FROM users WHERE username='$email' AND password='$password'") or die(mysql_error());
while($row = mysql_fetch_array($result)) {
if(mysql_num_rows($result) > 0) {
$_SESSION['user_pid'] = $row['user_pid'];
$_SESSION['firstname'] = $row['first_name'];
$_SESSION['lastname'] = $row['last_name'];
header("Location: ../protected/home.php");
} else {
$userid_generator = uniqid(rand(), false);
$date = date("Y/m/d");
mysql_query("INSERT INTO users (user_pid, username, password, datetime_registered)
VALUES('$userid_generator', '$email', '$password', '$date')")or die(mysql_error());
$_SESSION['userid'] = $userid_generator;
$_SESSION['firstname'] = $row['first_name'];
$_SESSION['lastname'] = $row['last_name'];
$leaders_query = "SELECT * FROM leaders";
$leaders = mysql_query($leaders_query);
$id = $row['id'];
mysql_query("INSERT IGNORE INTO friends (node1id, node2id, is_leader, friends_since, friend_type)
VALUES('$id', '$userid_generator', 'Yes', '$date', 'full)")or die(mysql_error());
}
}
?>
由於某種原因while循環似乎不起作用。當我在while循環中插入內容時,它留下一個空白屏幕。任何幫助?如果內容處於while循環中,則不處理頁面