当两个表单由两个用户提交相同的时间时,更新数据库中的错误值
问题描述:
您好,感谢您查看我的代码!当两个表单由两个用户提交相同的时间时,更新数据库中的错误值
嗯,当两个用户同时提交两个表单时,我正面临问题。我会尽力阐述它。
我的表格,以更新三个用户价值,
我的PHP:
<?php
set_time_limit(60);
if (isset($_POST['submit-buy'])) {
$buy_id = $_POST['buy_id'];
$buyer_id = $_POST['buyer_id'];
$buy_value = $_POST['buy_value'];
$owner_id = $_POST['owner_id'];
// more function goes here and returns value below i am also using if else to check if any value change it gives error msg to slow down
// $petvalue = 100000;
// $pet_earn = 5500;
// $check_petcash = 10000000;
// $pet_newvalue = 110000;
// $pet_updateoid = 1;
// $pettobuy = 2;
// first
$check_petcash = $pet_user->cash; //checking before updating
$pet_newcash = round($check_petcash + $pet_earn); // pet new cash
$upet_newvalue = mysql_query("UPDATE members SET value='$pet_newvalue', cash='$pet_newcash', ownerid='$pet_updateoid' WHERE id='$pettobuy'");
// second
// $old_owner = 3;
$ex_owner_cash = $oldowner->cash; //checking before updating
$ex_owner_newcash = round($ex_owner_cash + $petvalue + $pet_earn); // old owner cash
$update_newcash = mysql_query("UPDATE members SET cash='$ex_owner_newcash' WHERE id='$old_owner'");
// and last
// $pet_buyvalue = 120000;
// $user_id = 1;
$new_user_cash = $new_owner->cash; //checking before updating
$new_ownercash = round($new_user_cash - ($pet_buyvalue - $pet_earn)); // user cash
$upadte_ownercash = mysql_query("UPDATE members SET cash='$new_ownercash' WHERE id='$user_id'");
$msg = '<span id="other-info-font">You bought pet yay!</span><br/>';
}
?>
当两个用户提交表单同时和一个具有快速净等不要出现的主要问题。一段时间其切割$ new_ownercash。某些时候只有第一个和第二个查询得到更新,第三个则没有任何更改,或者(我的意思是所有计算在第二个和第三个查询中都出错)与其他用户提交表单一样。我有很多用户和它的游戏购买和销售,我们正在进行beta测试,所以仍然有时间来解决它。
这发生在所有用户在同一时间玩游戏并且弄乱了所有东西。我很清楚,因为我对此很陌生。
感谢
答
您还没有给出变量$old_owner
值!同上$user_id
顺便说一句 - 停止使用mysql_库,因为它们已被弃用。也看看SQL注入 - 这是危险的,你的脚本充满了可能性。
编辑
您正在使用的第二和第三更新相同WHERE
条款。因此,“同时”运行脚本将取决于如何更新表格。
当然$old_owner
和$user_id
在脚本的两次执行中应该是不同的?
好吧,我忘了添加他们在帖子中,但我们有他们 – deerox 2013-03-13 05:44:01
@deerox - 那么你还没有添加其他的东西?您发布的帖子是否重现了问题? (请注意使用已弃用的库和SQL注入) – 2013-03-13 05:46:02
感谢您的回复,我添加了所有缺少的内容。并为我期待图书馆和SQL注入thingy :) – deerox 2013-03-13 05:50:42