2014-01-17 28 views
0

我在第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

您在哪個環境下編程?也許Netbeans是一個想法?它會幫助你進行調試。 – Pakspul

+0

我使用記事本++我試過其他程序,如aptana studio和netbeans,但是我誠實地喜歡記事本++,僅僅是因爲它的簡單 – user3208543

回答

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,並使用PDOMySQLi - this article將幫助您決定哪個。如果您選擇PDO,here is a good tutorial

並且不使用md5存儲用戶密碼,這與純文本差不多

+0

+1還提到了不推薦使用的'mysql_'擴展名。 – Houssni

+0

非常感謝,我只是新的PHP,所以我認爲這將是一件好事,開始與 – user3208543

相關問題