我正在尝试为我的网站创建一个简单的注册脚本,但是查询有问题或我的代码有问题。
有问题的查询是这样的(再次更新):
<?php
session_start();
$mysqlusr = "website";
$mysqlpass = "OOPS!";
$mysqlhost = "localhost";
$mysqldb = "website";
$username = $_REQUEST['username'];
$password = $_REQUEST['password'];
$email = $_REQUEST['email'];
$day = $_REQUEST['day'];
$month = $_REQUEST['month'];
$year = $_REQUEST['year'];
$emailcheck;
$daycheck;
$monthcheck;
$yearcheck;
$usernameinuse;
$attempt = $_REQUEST['attempt'];
$dbhandle = mysql_connect($mysqlhost, $mysqlusr, $mysqlpass);
$selected = mysql_select_db("website") or die("Could not select database");
if ($attempt == true && $usernameinuse == false) {
$query2 = msql_query("INSERT INTO users (username, password, email, day, month, year) VALUES ('$username', '$password', '$email', '$day', '$month', '$year')");
} else {
if ($attempt == true && $usernameinuse == true) {
echo '<div class="alert alert-error"><b>Oh Snap!</b> Username Or Email is in use!</div>';
}
}
if ($_SESSION['state'] == 'logged-in') {
echo '<div class="alert alert-error"><b>Oh Snap!</b> You are already logged in!</div>';
} elseif ($_SESSION['state'] == 'no-user') {
echo '
<form action="register.php" metod="post">
Username: <input type="text" name="username" value="" MAXLENGTH="16" /><br>
Password: <input type="password" name="password" value="" MAXLENGTH="25"/><br>
Email<br><small>(Make sure this is your correct email as you will need to confirm your user!)</small>:<br> <input type="text" name="email" value=""MAXLENGTH="50"/><br>
Day of Birth: <select name="day">';
for ($i = 1; $i <= 31; $i++) {
echo '<option value=' . $i . '>' . $i . '</option>';
}
echo '
</select><br>
Month of Birth: <select name="month">
<option value="1">January</option>
<option value="2">February</option>
<option value="3">March</option>
<option value="4">April</option>
<option value="5">May</option>
<option value="6">June</option>
<option value="7">July</option>
<option value="8">August</option>
<option value="9">September</option>
<option value="10">October</option>
<option value="11">November</option>
<option value="12">December</option>
</select><br>
Year of Birth: <select name="year">';
for ($i = 2014; $i > 1900; $i--) {
echo '<option value=' . $i . '>' . $i . '</option>';
}
echo '</select>
<br>
<button type="submit" name="attempt" value="true" class="btn btn-primary"><i class="icon-file"></i> Register</button>
</form>
';
}
if ($attempt == true) {
$query = mysql_query("SELECT * FROM users WHERE username = '" . $username . "' OR email = '" . $email . "'");
if (mysql_num_rows($query) > 0) {
$usernameinuse = true;
} else {
$usernameinuse = false;
}
}
?>
显然,我必须添加更多文字,嗯....在这里!