MySQL:如何减去更新

时间:2012-12-12 14:58:38

标签: php mysql sql database

我需要减去一个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');
?>

+1工作完美但它不起作用-5 ...我怎么能这样做才能得到-5分?

2 个答案:

答案 0 :(得分: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); 

后续问题:这两列的数据表是什么?他们是未签名还是已签名?

答案 1 :(得分:0)

你用第二个语句覆盖第一个语句。试试这个:

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