简体   繁体   中英

form submit is not working when i click button

Why isn't my form working and why are there no errors showing? When I click the submit button nothing happens, here is my code:

<?php
$list_of_product=$p->loadSearchProduct($searchkey);

foreach ($list_of_product as $product) {
   echo "<tr>"
   .'<form id ="myForm" action = "InsertOrders.php" method = "POST">'
   ."<td>".$product->prodname."</td>"
   ."<td>".$product->price."</td>"
   ."<td>".$product->total." "."Piece(s)"."</td>"
   ."<td>".$product->remaining_stock." "."Piece(s)"."</td>"
   ."<td>".$product->sold_stock."</td>"
   ."<td>"."<input class='form-control' name='qty' type='text' required/>"."</td>"   
   ."<td>"."<button type='submit' id='sub' class='btn btn-primary'>"."<b>Add to List</b>"."</button>"."</td>"
   ."</form>"
   ."</tr>";
}
?>

In this case you have several forms with the same id.

When you click submit, it es not specific witch one is clicked.

EDIT

        $count = 0;
foreach ($list_of_product as $product) {
       echo "<tr>"
       .'<form id ="myForm" action = "InsertOrders.php" method = "POST">'
       ."<td>".$product->prodname."</td>"
       ."<td>".$product->price."</td>"
       ."<td>".$product->total." "."Piece(s)"."</td>"
       ."<td>".$product->remaining_stock." "."Piece(s)"."</td>"
       ."<td>".$product->sold_stock."</td>"
       ."<td>"."<input class='form-control' name='qty' type='text' required/>"."</td>"   
       ."<td>"."<button type='submit' id='sub".$count."' class='btn btn-primary'>"."<b>Add to List</b>"."</button>"."</td>"
       ."</form>"
       ."</tr>";
       $count++;
    }

When you use an counter, you can check in you InsertOrders.php which one is clicked. Its not the best way, but it will be work.

i think if you can use form tags outside of the foreach , it will submit. Or else try remove 'id' attribute in your code.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM