我在第4行,大括号上收到错误。据我所知,支架需要在那里。我该如何解决这个问题?
<?php
include('config.php');
// for the registration script we need a html form
if($_SERVER['REQUEST_METHOD'] == 'POST' {
$username = mysql_real_escape_string($_POST['username']);
$password = mysql_real_escape_string(md5($_POST['password']));
//retrieve the input from the user and encrypt the password with md5
} if(empty($username)) {
echo("Please enter a Username");
} else {
if(empty($password)) {
echo("Please enter a password");
} else {
//check if username already exists
$query = mysql_query("SELECT * FROM users WHERE username='$username'");
$rows = mysql_num_rows($query);
//with mysql_query you call a sql command
if($rows > 0) {
die("Username taken !!");
} else {
$user_input = mysql_query("INSERT INTO users (username , password) VALUES ('$username' , '$password')");
echo("Successfully Registered ");
}
}
}
?>
答案 0 :(得分:4)
更改
if($_SERVER['REQUEST_METHOD'] == 'POST' {
要
if($_SERVER['REQUEST_METHOD'] == 'POST') {
您错过了结束)
另外Don't use mysql_*
functions in new code。它们不再被维护and are officially deprecated。请参阅red box?转而了解prepared statements,并使用PDO或MySQLi - this article将帮助您确定哪个。如果您选择PDO here is a good tutorial。
并且不使用MD5存储用户密码,这几乎和普通文本
一样糟糕