简体   繁体   中英

PHP list created using While loop - How update all using submit button

Happy Evening All,

Group submission has been executed without collecting the First name and Last name we would like to collect Firstname and Lastname, re-posting to the group user to enter First name and Last name.

Here below is the code used to list the group information with INPUT field to collect the First name and Last name.

Any Idea on how to post all the Input data of the first name and last name into DB in one submit button.

Any help would be grateful.

 $Group_ID = '22125';

mysql_connect('localhost','root','') or die (mysql_error ()); 
mysql_select_db("GroupDB") or die (mysql_error ()); 

$strSQL = "SELECT ID, firstname, lastname from people where pay_orderid ='$Group_ID'";
mysql_query($strSQL) or die (mysql_error()); 
$query = mysql_query($strSQL);

echo "<table class='table-responsive'><thead><tr><th>First Name</th><th>Last Name</th></tr></thead><tbody>";

while($row = mysql_fetch_array($query)) {
$CurID= $row['ID']; 
$firstname= $row['firstname']; 
$lastname = $row['lastname'];
echo "<tr><td>".$Group_ID."</td><td>".$CurID."</td><td><input value='".$firstname."'></td><td><input value='".$lastname."'></td></tr>";
}

echo "</tbody></table>";?>

Working Solution: add name to the input field with [] example.

<td><input name= "firstname[]"  value='".$firstname."'></td>


foreach($_POST['firstname'] as $row=>$fname)
{    
$up_firstname = mysql_real_escape_string($fname); 
$up_CurID= mysql_real_escape_string($_POST['CurID'][$row]);
$up_lastname= mysql_real_escape_string($_POST['lastname'][$row]);

$involv = "UPDATE `people` SET `firstname` = '$up_firstname', `lastname` = '$up_lastname'  WHERE `people`.`ID` = '$up_CurID';"; 
mysql_query($involv);

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