edit.php coding...

<?php $uid = (int)$_GET['id']; ?>
<form action="update.php" name="myform" method="post" onsubmit="return(validateform());">
    <input type="hidden" name="edited" value="<?=$uid;?>">

        $tariff_query = mysql_query("SELECT * FROM ebvouchertariffs WHERE VoucherID_Fk = $uid");
        echo "<table width=960 align=center cellspacing=0 cellpadding=0>
            <td width=68 height=50 class=tabtext>SL.NO</td>
            <td width=106 class=tabtext>DATE</td>
            <td width=204 class=tabtext>PARTICULARS</td>
            <td width=117 class=tabtext>NO OF NIGHTS</td>
            <td width=104 class=tabtext>RATE</td>
            <td width=177 class=tabtext>PRICE</td>
            <td class=tabtext colspan=5>TAX %</td>
        while($t_row = mysql_fetch_array($tariff_query))
          echo "<tr class=tabform>
          <td height=30><input type=text name=slno[] value= ". $t_row['TariffSlNo'] ." size=2></td>
          <td height=8><input type=text value=". $t_row['TariffDate'] ." size=10 name=date[] id=SelectedDate onClick=GetDate(this); readonly=readonly/></td>
          <td height=8><input size=24 type=text name=particulars[] placeholder=\"Description\" value=". $t_row['TariffParticulars'] ."></td>
          <td height=8 colspan=8>";
         echo "<select name=noofnights[] value= >";
         echo "<option>" . $t_row['NoOfNights'] . "</option>";
         echo "<option></option>"; 
         echo "<option value=1>1</option>
          <option value=2>2</option>
          <option value=3>3</option>
          <option value=4>4</option>
          <option value=5>5</option>
          <option value=6>6</option>
          <option value=7>7</option>
          <option value=8>8</option>
          <option value=9>9</option>
          <option value=10>10</option>
          <option value=11>11</option>
          <option value=12>12</option>
          <option value=13>13</option>
          <option value=14>14</option>
          <option value=15>15</option>
          <option value=16>16</option>
          <option value=17>17</option>
          <option value=18>18</option>
          <option value=19>19</option>
          <option value=20>20</option>
          <option value=21>21</option>
          <option value=22>22</option>
          <option value=23>23</option>
          <option value=24>24</option>
          <option value=25>25</option>
          <option value=26>26</option>
          <option value=27>27</option>
          <option value=28>28</option>
          <option value=29>29</option>
          <option value=30>30</option>
          <option value=31>31</option>";
         echo "</select>"; 
    echo " <input size=14 type=text onKeyUp=return valtxt(this) name=rate[] value=". $t_row['TariffRate'] .">
           <input size=14 type=text name=price[] value=". $t_row['TariffRate'] ." readonly=readonly>
    <input size=9 type=text name=tax[] onKeyUp=\"return valtxt(this)\" value=". $t_row['TariffPrice'] ." >
    <input size=1 type=hidden name=taxtotal[] readonly=readonly value= ></td>
<input name="submit_val" type="submit" value="Update Voucher" />

and updatedb.php coding...


    $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 = "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_query($e_tariff)or die(mysql_error());

here i edit and update the existing records using php mysql. i already inserted dynamic row values to mysql. now i can fetch dynamic row values correctly (dynamic row means -> sometime 3 rows, 5 rows, 10 rows, 20rows, etc..., like that depend upon the user). but i cannot able to update the existing record. thats the problem here. i edit the records and then changes something in every row. but it updates last row values in all row... i attached an image here. look at this. it updates every row wrongly. f20c666f729e7b8711929c5f8b85cd78 if anyone knows where is the error tell me...

I'm not sure if I understand you but here is what I understand and my answer for it.
I think you have a users system every user has his own records,when you are trying to update the records it is automatically updating the last record.

if I'm right then here is my answer:
you need to bring the record id from the database(the record that you want to edit) then but it in the query,So what you need is 2 tables:

the 'services' table should have a field which contain either the 'user id' or the 'username'
so when a user post a service it will have automatically his 'username' or his 'user id'
after that when you are editing the record and click submit it will edit the record from the record 'id'

I hope I was able to give you the idea XD

but i'm already fetch the record correctly. foreach update is my problem. i got my every record based on the userid...

yes that is correct but your problem isn't with the user id !
your problem is with the 'record id'
the field 'user_id' in the services table ,in my example, gives you the ability of foreach the user posts, the 'record_id' will give you the abilty of editing a spesific record.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.