Mysql wrongly update the dynamic row records [duplicate]

空扰寡人 提交于 2020-01-06 08:30:07

问题


I trying to update my dynamic row values here. When i insert a new voucher record it could inserted the values correctly into database. When i edit the record values that time also it fetch the values from database correctly. But updation is my problem. It always update the last row values in all rows..

Previously i posted another question here related to this question but still didn't clear this error. Here is the link for another same question

Updation page PHP Coding :

if(isset($_POST['submit_val']))
    {
    $uid = (int)$_POST["edited"];
    foreach( $_POST['slno'] as $key=>$slno ) 
    {
        $e_date = $_POST['date'][$key];
        $e_particulars = $_POST['particulars'][$key];
        $e_noofnights = $_POST['noofnights'][$key];
        $e_rate = $_POST['rate'][$key];
        $e_price = $_POST['price'][$key];
        $e_tax = $_POST['tax'][$key];
        $e_nettotal = $_POST['nettotal'];
        $e_totalamount = $_POST['totalamount'];
        $e_finaltotal = $_POST['finaltotal'];

        $e_slno = mysql_real_escape_string($e_slno);
        $e_date = mysql_real_escape_string($e_date);
        $e_particualrs = mysql_real_escape_string($e_particulars);
        $e_noofnights = mysql_real_escape_string($e_noofnights);
        $e_rate = mysql_real_escape_string($e_rate);
        $e_price = mysql_real_escape_string($e_price);
        $e_tax = mysql_real_escape_string($e_tax);
        $e_nettotal = mysql_real_escape_string($e_nettotal);
        $e_totalamount = mysql_real_escape_string($e_totalamount);
        $e_finaltotal = mysql_real_escape_string($e_finaltotal);
        $e_tariff = mysql_query("UPDATE ebvouchertariffs SET TariffSlNo = '$e_slno', TariffDate = '$e_date', TariffParticulars = '$e_particulars', NoOfNights = '$e_noofnights', TariffRate = '$e_rate', TariffPrice = '$e_price', TariffTax = '$e_tax', TariffNetTotal = '$e_nettotal', TariffAddTotal = '$e_totalamount', TariffFinalTotal = '$e_finaltotal', ModifiedOn = NOW() WHERE VoucherID_Fk = '$uid'");
    }
mysql_close($link);
    }

I attached a few images here..

Before Updation:

After Updation

You can see above images here. When i update a row it always updates the last row values in all rows.. Where i made a mistake?


回答1:


because your where condition is wrong,

have a look at

$e_tariff = mysql_query("UPDATE ebvouchertariffs SET TariffSlNo = '$e_slno', TariffDate = '$e_date', TariffParticulars = '$e_particulars', NoOfNights = '$e_noofnights', TariffRate = '$e_rate', TariffPrice = '$e_price', TariffTax = '$e_tax', TariffNetTotal = '$e_nettotal', TariffAddTotal = '$e_totalamount', TariffFinalTotal = '$e_finaltotal', ModifiedOn = NOW() WHERE VoucherID_Fk = '$uid'");

the $uid pointing to wrong key, the key should come from inside of foreach




回答2:


I am not very sure about it. But as much as I hv come across php I hv never seen "Key" of a multi dimensional associative array as being used as second index parameter while displaying data from an array!!! I cant comment so i posted this as an answer... Sry. :)



来源:https://stackoverflow.com/questions/20794722/mysql-wrongly-update-the-dynamic-row-records

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!