Mysql错误地更新了动态行记录

时间:2013-12-27 04:27:28

标签: javascript php mysql foreach

我尝试在此处更新动态行值。当我插入新的凭证记录时,它可以正确地将值插入数据库。当我编辑那段时间的记录值时,它也正确地从数据库中获取值。但更新是我的问题。它总是更新所有行中的最后一行值。

之前我在这里发布了另一个与此问题相关的问题,但仍然没有清除此错误。 Here is the link for another same question

更新页面PHP编码:

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

我在这附上了一些图片..

更新前:

enter image description here

更新后

enter image description here

您可以在此处查看上面的图片。当我更新一行时,它总是更新所有行中的最后一行值。我犯了哪个错误?

2 个答案:

答案 0 :(得分:0)

因为你的情况不对,

看看

$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'");

$uid指向错误的密钥,密钥应来自foreach内部

答案 1 :(得分:0)

我不太确定。但是,尽管我遇到了php,但我从来没有看到多维关联数组的“Key”被用作第二个索引参数,同时显示来自数组的数据!我不能发表评论,所以我发布了这个答案...... Sry。 :)