1

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

4

2 回答 2

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); 

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

于 2012-12-12T15:02:12.093 回答
0

您正在用第二个语句覆盖第一个语句。尝试这个:

$insert = "UPDATE `users` SET `points` = (`points`-5), `lodd` = (`lodd` +1) WHERE `username` = '".$username."'";
mysql_query($insert); 
于 2012-12-12T15:05:36.407 回答