Please help me how to insert data values from table rows to database when only the checkboxes are checked and submit. I am new to php please respect my post. thank you in advance help meeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee
This is my html and php code:
<table border ='1' align='center' width='50%'>
<tr>
<td bgcolor='yellow'><center></td>
<td bgcolor='yellow'><center>Name</td>
<td bgcolor='yellow'><center>Address</td>
<td bgcolor='yellow'><center>Email</td>
<td bgcolor='yellow'><center>Option</td>
</tr>
<?php
include("connections.php");
//retrieving data from temporary table that needs to be validate first by the administrator before it goes to the official table
$retrieve_query = mysqli_query($connections, " SELECT * FROM temptbl WHERE status='pending'");
//retrieving data from temptbl
while($row_users = mysqli_fetch_assoc($retrieve_query)) {
$db_id = $row_users["temp_id"];
$ins_name = $row_users["name"];
$ins_address = $row_users["address"];
$ins_email = $row_users["email"];
$ins_password = $row_users["password"];
//displaying table rows with checkbox from temptbl
echo "<form method='POST' action='accept.php'>";
echo " <tr>
<td><input type='hidden' name='temp_id' value='$db_id'><input type='checkbox' name='validate[]' value='accepted' ></td>
<td>$ins_name</td>
<td>$ins_address</td>
<td>$ins_email</td>
<td><a href='confirm_delete.php'>Delete</a></td>
</tr>";
}
?>
</table>
<hr>
<input type="submit" name="accept" value="Accept">
</form>
AND this is the accept.php file:
<?php
include ("connections.php");
//if accept button submits, it will insert all the checked checkboxes that contains the data from table rows
if(isset($_POST['accept'])) {
//inserting values to official table
$query = mysqli_query($connections, "INSERT INTO mytbl (name,address,email,password,account_type)
VALUES('$ins_name','$ins_address','$ins_email','$ins_password','2') ");
//and updates all pending to good or done
mysqli_query($connections, "UPDATE temptbl SET status='good' WHERE status='pending'");
//notifications
echo "<script language='javascript'>alert('New record has been inserted!')</script>";
echo "<script>window.location.href='index.php';</script>";
}
}
?>
Aucun commentaire:
Enregistrer un commentaire