2012-12-12 80 views
1

我需要減去mysql更新。這裏是代碼:MySQL:如何減去更新

<?php 
session_start(); 
//=============Configuring Server and Database======= 
$host  = 'localhost'; 
$user  = 'root'; 
$password = ''; 
//=============Data Base Information================= 
$database = 'login'; 

$conn  = mysql_connect($host,$user,$password) or die('Server Information is not Correct'); //Establish Connection with Server 
mysql_select_db($database,$conn) or die('Database Information is not correct'); 

//===============End Server Configuration============ 

//=============Starting Registration Script========== 


$username = mysql_real_escape_string($_POST['txtusername']); 

//=============To Encrypt Password=================== 

//============New Variable of Password is Now with an Encrypted Value======== 


$insert = "UPDATE `users` SET `points` = (`points`-5) WHERE `username` = '".$username."'"; 
$insert = "UPDATE `users` SET `lodd` = (`lodd` +1) WHERE `username` = '".$username."'"; 

mysql_query($insert); 


header('location: succes.php'); 
?> 
<?php 
session_start(); 
//=============Configuring Server and Database======= 
$host  = 'localhost'; 
$user  = 'root'; 
$password = ''; 
//=============Data Base Information================= 
$database = 'login'; 

$conn  = mysql_connect($host,$user,$password) or die('Server Information is not Correct'); //Establish Connection with Server 
mysql_select_db($database,$conn) or die('Database Information is not correct'); 

//===============End Server Configuration============ 

//=============Starting Registration Script========== 


$username = mysql_real_escape_string($_POST['txtusername']); 

//=============To Encrypt Password=================== 

//============New Variable of Password is Now with an Encrypted Value======== 


$insert = "UPDATE `users` SET `points` = (`points`-5) WHERE `username` = '".$username."'"; 
$insert = "UPDATE `users` SET `lodd` = (`lodd` +1) WHERE `username` = '".$username."'"; 

mysql_query($insert); 


header('location: succes.php'); 
?> 

+1工作完美,但它不工作-5 ...我怎麼能讓他們得到-5分?

+0

你是什麼意思,它不起作用。是否有錯誤或結果不好? – Marc

回答

2

+1正常工作,因爲帶有-5的查詢將永遠不會被調用,因爲它被+1的查詢覆蓋。

你應該有這樣的代碼,(雖然這不是一個正確

$insert = "UPDATE `users` SET `points` = (`points`-5) WHERE `username` = '".$username."'"; 
mysql_query($insert); 

// other codes 

$insert = "UPDATE `users` SET `lodd` = (`lodd` +1) WHERE `username` = '".$username."'"; 
mysql_query($insert); 

跟進的問題:什麼是兩列的dataypes?他們是未簽名還是簽名?

+0

我將在8分鐘!但它工作得很好:)謝謝 – carl

0

你用第二條語句覆蓋第一條語句。試試這個:

$insert = "UPDATE `users` SET `points` = (`points`-5), `lodd` = (`lodd` +1) WHERE `username` = '".$username."'"; 
mysql_query($insert);