0

this is the image

For example:

I input a number on "USED(kl)" in its textbox and the row where "KILOGRAM/S" is will be subtracted from the number I input on the textbox;

When I click update button, it should only affect the row where it belongs whereas the textbox below are affected like the SAVE button does.

Here's the code:

while ($row = mysql_fetch_array($resval))
{

    //  $amount  = $row['amount'] == 0 ? '' : number_format($row['amount']);
    echo '<tr>
        <td name="getit">'.$row['id_raw'].'</td>
        <td>'.$row['prodname'].'</td>
        <td name="getit1">'.$row['kl'].'</td>
        <td>'.$row['ounce'].'</td>
        <td>'.$row['gram'].'</td>
        <td>'.$row['quantity'].'</td>
        <td>'.$row['price'].'</td>
        <td>'.$row['supplier'].'</td>
        <td>'.$row['dateclaim'].'</td>
        <td>'.$row['shelflife'].'</td>
        <td><input step="any" type=number name="aji" style="width:100%;"></td>
        <td><center><input type=submit value="UPDATE" id="button1" name="button1"></center></td>
    </tr>';

There's no javascript for identifying the button just this PHP code:

if (isset($_POST['a1']) || isset($_POST['a2']) || isset($_POST['a3']) ||  isset($_POST['a4']) ||  isset($_POST['a5']) ||  isset($_POST['a6']) ||  isset($_POST['a7']) ||  isset($_POST['a8']) ||  isset($_POST['a9']) ||  isset($_POST['a10']))

 {
     //Retrieve input from textboxes
//  $SNUM = $_POST['a1'];
$y2 = $_POST['a2'];
$y3 = $_POST['a3'];
$y4 = $_POST['a4'];
$y5 = $_POST['a5'];
$y6 = $_POST['a6'];
$y7 = $_POST['a7'];
$y8 = $_POST['a8'];
$y9 = $_POST['a9'];
$y10 = $_POST['a10'];




//INSERT RECORD To tblregdetails
$sql = "INSERT INTO rawitems values('" . $SNUM . "','" . $y2 . "','" . $y3 . "','" . $y4 . "','" . $y5 . "','" . $y6 . "','" . $y7 . "','" . $y8 . "','" . $y9 . "','" . $y10 . "')";'

Thank you for your help :)

shinbona
  • 21
  • 5
  • Possible duplicate of [How to get mysqli error in different environments?](https://stackoverflow.com/questions/22662488/how-to-get-mysqli-error-in-different-environments) –  Feb 13 '18 at 14:32
  • The case is, the PRODUCT ID should be a textbox in order to get values from its row but I'm confused how to get it without affecting any other rows. – shinbona Feb 13 '18 at 16:17
  • You need to identify each row with a unique ID. For this you can use the product ID (unique product identifier that you are using in database). Then use that same id as button's id because you need to know which button represents which row (so each button has to have its rows id). Then put the php code to update the relevant row code. Since you are 'updating', you have to use update query, for which you again need that unique id. In other words, you are treating each row as a separate form, with its own submission button. – DarthWader Feb 13 '18 at 16:39

1 Answers1

0

You shouldn't have the same id on multiple elements. I would need to see your javascript, but just try referencing the button by class

    while ($row = mysql_fetch_array($resval))
{

//  $amount  = $row['amount'] == 0 ? '' : number_format($row['amount']);
    echo '<tr>
            <td name="getit">'.$row['id_raw'].'</td>
            <td>'.$row['prodname'].'</td>
            <td name="getit1">'.$row['kl'].'</td>
            <td>'.$row['ounce'].'</td>
            <td>'.$row['gram'].'</td>
            <td>'.$row['quantity'].'</td>
            <td>'.$row['price'].'</td>
            <td>'.$row['supplier'].'</td>
            <td>'.$row['dateclaim'].'</td>
            <td>'.$row['shelflife'].'</td>
            <td><input step="any" type=number name="aji" style="width:100%;"></td>
            <td><center><input type=submit value="UPDATE" class="button-save-update" name="button1"></center></td>
            </tr>';