我有下面表表示:行插入與複選框
<form method="post" action="insertassign_process.php">
<table class="table table-bordered table-responsive">
<?php
echo"<thead>
<tr><th>Tenant ID</th>
<th>Tenant ZIP</th>
<th>Process server ID</th>
<th>Process Server Name</th>
<th>Phone Nmuber</th>
<th>Select Process Server</th>
<th>Assign Proces Server</th>
</tr>
</thead>";
include("connection.php");
extract($_REQUEST);
$SQLSELECT = "SELECT * FROM users where zip_codes='$zip'";
$result_set = mysql_query($SQLSELECT) or die(mysql_error());
while($row = mysql_fetch_array($result_set))
{
?>
<tr>
<td><input type="text" readonly name="t_id[]" value="<?php echo $t_id; ?>"/></td>
<td><input type="text" readonly name="zip[]" value="<?php echo $zip; ?>"/></td>
<td><input type="text" readonly name="pr_id[]" value="<?php echo $row['id']; ?> "></td>
<td><input type="text" readonly name="fullname[]" value="<?php echo $row['first_name'].' '.$row['last_name']; ?>"</td>
<td><?php echo $row['phone_no']; ?></td>
<td><input type="checkbox" name="name[]" select="selected" value="<?php echo $row["t_id"]; ?>" /></td>
<td><input type="radio" name="assign_process" value="1" /></td>
</tr>
<?php
}
?>
</table><button type="submit" class="btn btn-primary button-loading" name="submit" data-loading-text="Loading...">Submit</button></form>
現在,當我檢查任何複選框(可以是多選擇),那麼選擇的該行的將被插入另一個表中的數據。我的查詢插入是:
<?php
session_start();
include("connection.php");
extract($_SESSION);
extract($_POST);
if(isset($_POST["submit"])==true)
{
$counter = count($_POST["name"]); /* COUNT THE PASSED ON NAME */
for($x=0; $x<=$counter; $x++){
if(!empty($_POST["name"][$x])){
$CUSTOMER_NAME = mysql_real_escape_string($_POST["t_id"][$x]);
$PI_ADDRESS = mysql_real_escape_string($_POST["pr_id"][$x]);
$qry="INSERT INTO select_process (id,tenant_select_id,process_select_id) VALUES ('','$CUSTOMER_NAME','$PI_ADDRESS')";
mysql_query($qry);
} /* END OF CHECKING THE CHECKBOX IF SELECTED */
} /* END OF FOR LOOP */
}
else{
echo"error";
}
?>
但是,當我選擇多行或任何然後它只插入第一行數據。
請停止使用PHP的過時mysql_ API – Strawberry