2013-03-15 79 views
1

我是PHP和mysql的新手。以下代碼來自登錄頁面。我想在一個名爲users的mysql數據庫中使用一個boolean(tinyint)值。如果「付款」字段的值爲0,我想將用戶發送到我的pay.php頁面,如果值爲1並且登錄詳細信息正確,我想將用戶發送到index.php。然而,代碼向pay.php發送用戶數據庫中的值是0還是1.任何幫助將不勝感激!從mysql字段中選擇數據使用值作爲php變量

$query = mysql_query("SELECT * FROM `users` WHERE username = '$username' AND password = '$password'") or die (mysql_error()); // mySQL query 

$r = mysql_num_rows($q); // Checks to see if anything is in the db. 
$row = mysql_fetch_array($query); 
if($row['paid'] == 0);{  //NOT WORKING!!!  
    header ("location:pay.php");// go to pay.php 
    exit();// Stops the rest of the script. 
} 

if ($r == 1) { // There is something in the db. The username/password match up. 
    $_SESSION['logged'] = 1; // Sets the session. 
    header ("location:index.php");// go to index.php 
} 
else { // Invalid username/password. 
    exit("Incorrect username/password!"); // Stops the script with an error message.   
} 
+4

[**請不要在新代碼'mysql_ *'功能**](HTTP://位.ly/phpmsql)。他們不再被維護[並且被正式棄用](http://j.mp/XqV7Lp)。看到[**紅框**](http://j.mp/Te9zIL)?學習[*準備的語句*](http://j.mp/T9hLWi),並使用[PDO](http://php.net/pdo)或[MySQLi](http://php.net/ mysqli) - [這篇文章](http://j.mp/QEx8IB)將幫助你決定哪個。如果你選擇PDO,[這裏是一個很好的教程](http://j.mp/PoWehJ)。 – 2013-03-15 19:31:41

+0

也注意到了這個'if($ r == 1){'$ r'的值是多少? – 2013-03-15 19:56:24

回答

1
if($row['paid'] == 0);{ 

擺脫分號的在那裏:

if($row['paid'] == 0){ 
+0

好的!半天浪費在流浪分號上!試圖給你投票,但我沒有足夠的聲譽! – 2013-03-15 20:45:10