2013-03-13 23 views
0

您好,感謝您查看我的代碼!當兩個表單由兩個用戶提交相同的時間時,更新數據庫中的錯誤值

嗯,當兩個用戶同時提交兩個表單時,我正面臨問題。我會盡力闡述它。

我的表格,以更新三個用戶價值,

我的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測試,所以仍然有時間來解決它。

這發生在所有用戶在同一時間玩遊戲並且弄亂了所有東西。我很清楚,因爲我對此很陌生。

感謝

回答

0

您還沒有給出變量$old_owner值!同上$user_id

順便說一句 - 停止使用mysql_庫,因爲它們已被棄用。也看看SQL注入 - 這是危險的,你的腳本充滿了可能性。

編輯

您正在使用的第二和第三更新相同WHERE條款。因此,「同時」運行腳本將取決於如何更新表格。

當然$old_owner$user_id在腳本的兩次執行中應該是不同的?

+0

好吧,我忘了添加他們在帖子中,但我們有他們 – deerox 2013-03-13 05:44:01

+0

@deerox - 那麼你還沒有添加其他的東西?您發佈的帖子是否重現了問題? (請注意使用已棄用的庫和SQL注入) – 2013-03-13 05:46:02

+0

感謝您的回覆,我添加了所有缺少的內容。併爲我期待圖書館和SQL注入thingy :) – deerox 2013-03-13 05:50:42

相關問題