Jump to content

PHP Forms and MySql


iamdaboss

Recommended Posts

Hi!

 

I have a PHP page which displays a table from MySQL. The table has four columns, the first three cannot be altered whereas the 'Final' column is read/write. So, this PHP page displays all the columns and has a text box for the fourth column('Final') displaying the existing value in a text box which can be changed by user and the same has to be updated in MySql table.

 

Therefore when the user changes the value of 'Final' and hits 'enter' key, the new 'Final' value and corresponding 'Value1' has to be submitted so that the database can be updated. This is not happening because if the database table has 100 columns I am displaying only 30 per page and the 'Value1' from the last row is being submitted.

 

Example:

 

'Value1' range is 1.....100

 

Page1: Displays a table with 30 rows with 'Value1' = 1....30

 

I change 'Final' = 'abc' of a row with 'Value1' = '20'

 

The form should return 'abc' and '20' .

But, the current code returns  'Value1' = '30'

 

Any help with this issue would be greatly appreciated.

 

Thank you

 

Code>>>

 

  <form id="form1" name="form1" method="post" action="">

    <table width="100%" border="1">

      <tr>

        <td>Value1</td>

        <td>Value2</td>

        <td>Value3</td>

        <td>Final</td>

      </tr>

      <?php do { ?>

        <tr>

          <td height="27"><label>

          <input type="text" readonly="readonly" size="12" style="border:hidden" name="Value1"

          id="Value1" value="<?php echo $row_Recordset1['Value1']; ?>" />

          </label>

          </td>

          <td><?php echo $row_Recordset1['Value2']; ?></td>

          <td><?php echo $row_Recordset1['Value3']; ?></td>

          <td><label>

            <input type="text" name="Finalval" id="Finalval" accept="text/plain" onchange="form.submit()" value="<?php echo

 

$row_Recordset1['Final']; ?>" />

          </label></td>

      </tr>

       

        <?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?>

    </table>

</form>

 

???

Link to comment
Share on other sites

You're creating a ton of table rows with an input box that has the same id every time. Of course it's only going to submit the last one.

 

I tried giving a different name for each input box and it works. When i hit submit the updated values are sent but all the values for the 30 rows are sent though i have changed only one input box. Any solutions for this problem ?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.