Swapnanil Saha
Swapnanil Saha

Reputation: 134

How to handle multiple submit buttons when the number of buttons is variable?

What i have tried to accomplish here is to fetch data from database and display it a form. How to name the submit buttons so that i can identify them on the actions page?

if(isset($_POST["sch"]))
      {
      $_SESSION['e']=$_POST["phon"];
      $result_set=mysql_query("select * from bill_info where      phone='".$_SESSION['e']."' and net_payable=0 order by bill_no");
      if($row=mysql_fetch_array($result_set))
      {      
      echo "<form name=\"shpen\" method=\"post\" action=\"vgbill2.php\"> <table border=\"0\">";
      do
      {
        echo "<tr><th>Bills</th><th>Action</th></tr>";
        echo "<tr><td>".$row[0]."</td><td><input type=\"submit\" name=\"".$row[0]."\" value=\"Generate\"></td></tr>";
        } while($row=mysql_fetch_array($result_set));
        //echo mysql_errno($con) . ": " . mysql_error($con) . "\r\n";
      echo "</table></form>";  
      }
      else echo "\r\n"." No bills pending for given phone number"." \r\n";
      } 

Upvotes: 0

Views: 119

Answers (2)

J.Beyer
J.Beyer

Reputation: 131

Use a button instead of an input:

echo '<button type="submit" name="bt_submit" value="'.$row[0].'">Generate</button>';

So you get the former name in $_POST['bt_submit'].

Upvotes: 1

techiefighter
techiefighter

Reputation: 1

Since you are creating dynamic form and submitting the data, you don;t have to follow any special naming convention. Please use submit button name as "Save" and set one hidden filed as BillId and in your action page, check if isset($_POST['Save']) { // Do actions based on $_POST['BillId']}.

Upvotes: 0

Related Questions