我的代码存在问题,因为当我按下更新按钮时,我希望它在重定向的页面上仅显示复选框中选中的字段。
我将发布第一页的代码,然后是第二页的代码,更新代码的位置以及网站页面的一些图片。
第一页:
代码首页:
<?php
if (isset ($_POST['search'])){
$ValueToSearch=$_POST['valueToSearch'];
$query1="SELECT * FROM `customer` AS cust,`type` AS type,`valability` AS val WHERE cust.Customer_ID=val.Customer_ID AND val.Insurance_ID=type.Insurance_ID AND CONCAT(cust.Customer_ID,cust.Employee_ID,cust.Name_c,cust.Surname_c,cust.brth,cust.phone,cust.adress,cust.email,type.series,type.type,type.name_i,type.Company_N,type.value,val.nr,val.entry_d,val.exp_d) LIKE '%".$ValueToSearch."%'";
echo "<!-- ". $query1 ." -->";
$search_result=filterTable($query1);
}else{
$query1 = "SELECT * FROM `customer`,`type`,`valability` WHERE customer.Customer_ID=valability.Customer_ID AND valability.Insurance_ID=type.Insurance_ID";
$search_result=filterTable($query1);
}
function filterTable($query1){
$connect=mysqli_connect("localhost" ,"root", "","asig");
$filter_Result=mysqli_query($connect,$query1);
return $filter_Result;
}
?>
<?php
if (isset($_POST['update'])) {
//$connect=mysqli_connect("localhost" ,"root", "","asig");
//$update_id=$_POST['checkbox'];
Header("Location: displayupdate.php");
//die();
//exit;
}else{
echo"can't redirect";
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Display Table </title>
<style>
table {
width: 100%;
background-color: #f1f1c1;
}
table ,tr, th, td
{
border:1px solid black;
border-collapse: collapse;
}
th,td{
padding: 5px;
}
</style>
</head>
<!--Beginning of CSS page-->
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css">
<body>
<div class="w3-display-container" style="margin-bottom:50px">
<img src="image2/Insurance-2.jpg" style="width:100%">
<div class="w3-display-bottomleft w3-container w3-amber w3-hover-orange w3-hide-small"
style="bottom:10%;opacity:0.7;width:70%">
<h2><b>4 Good Reasons<br>For being a SafeAsig client</b></h2>
</div>
</div>
<!--Buton pentru display timp-->
<button type="button"
onclick="document.getElementById('demo').innerHTML = Date()">
Click me to display Date and Time.</button>
<p id="demo"></p>
<form action="display.php" method="post">
<input type="text" name="valueToSearch" placeholder="ValueToSearch">
<input type="submit" name="search" value="Filter">
<input type="submit" name="delete" value="Delete">
<input type="submit" name="update" value="Update">
<hr>
<h1 style="text-align:center;"> Date Clienti</h1>
<table>
<tr>
<th></th>
<th>id</th>
<th>Nume</th>
<th>Prenume</th>
<th>DataNastere</th>
<th>telefon</th>
<th>Adresa</th>
<th>email</th>
<th>serie</th>
<th>type</th>
<th>numeAsig</th>
<th>Companie</th>
<th>Valoare></th>
<th>Numar</th>
<th>DataIntrare</th>
<th>DataExpirare</th>
</tr>
<?php while ($row=mysqli_fetch_array($search_result)):?>
<tr>
<td><input type="checkbox" name="checkbox[]" value="<?php echo $row['Customer_ID']; ?>"/></td>
<td><?php echo $row['Customer_ID']; ?></td>
<td><?php echo $row['Name_c']; ?></td>
<td><?php echo $row['Surname_c']; ?></td>
<td><?php echo $row['brth']; ?></td>
<td><?php echo $row['phone']; ?></td>
<td><?php echo $row['adress']; ?></td>
<td><?php echo $row['email']; ?></td>
<td><?php echo $row['series']; ?></td>
<td><?php echo $row['type']; ?></td>
<td><?php echo $row['name_i']; ?></td>
<td><?php echo $row['Company_N']; ?></td>
<td><?php echo $row['value']; ?></td>
<td><?php echo $row['nr']; ?></td>
<td><?php echo $row['entry_d']; ?></td>
<td><?php echo $row['exp_d']; ?></td>
</tr>
<?php endwhile;?>
</table>
</form>
<!--Link pentru inserari-->
<a href="http://localhost/website/main_entry_page.php">Inserare Clienti </a> <br><br>
<a href="http://localhost/website/insert_employee.php">Inserare angajati</a> <br><br>
<div class="w3-row w3-container" style="margin:50px 0">
<div class="w3-half w3-container">
<div class="w3-topbar w3-border-amber">
<img src="image2/profesionalism.jpg" style="width:100%">
<h2>Profesionalism and dedication</h2>
<p>Only for our clients , the best services provided.</p>
</div>
</div>
<div class="w3-half w3-container">
<div class="w3-topbar w3-border-amber">
<img src="image2/protection.jpg" style="width:100%">
<h2>100% protection</h2>
<p>Up to 100% protection with our wide varaity insurances.</p>
</div>
</div>
</div>
<div class="w3-row w3-container" style="margin:50px 0">
<div class="w3-half w3-container">
<div class="w3-topbar w3-border-orange">
<img src="image2/stability.jpg" style="width:100%">
<h2>Stability all times</h2>
<p>Wherever you travel our services provide stability.</p>
</div>
</div>
<div class="w3-half w3-container">
<div class="w3-topbar w3-border-orange">
<img src="image2/support.jpg" style="width:100%">
<h2>For good and worst</h2>
<p>Don't wait until it is to late.</p>
</div>
</div>
</div>
<?php
if (isset($_POST['delete'])) {
$connect=mysqli_connect("localhost" ,"root", "","asig");
$del_id = $_POST['checkbox'];
while(list($key, $val) = @each($del_id)){
mysqli_query($connect, "delete from customer where customer_id = $val");
}
}
?>
</body>
</html>
图片第二页:
代码第二页:
<html>
<?php
//Connect to database
$connect=mysqli_connect("localhost" ,"root", "","asig");
//Select database
mysqli_select_db($connect,'asig');
//Select Query
$sql = "SELECT * FROM `customer`,`type`,`valability` WHERE customer.Customer_ID=valability.Customer_ID AND valability.Insurance_ID=type.Insurance_ID";
//Execte query
$records=mysqli_query($connect,$sql);
?>
<head>
</head>
<body>
<table>
<tr>
<th>id</th>
<th>Nume</th>
<th>Prenume</th>
<th>DataNastere</th>
<th>telefon</th>
<th>Adresa</th>
<th>email</th>
<th>serie</th>
<th>type</th>
<th>numeAsig</th>
<th>Companie</th>
<th>Valoare></th>
<th>Numar</th>
<th>DataIntrare</th>
<th>DataExpirare</th>
</tr>
<?php
while($row=mysqli_fetch_array($records)){
echo "<tr><form action=update.php method=post>";
// echo "<td><input type=checkbox name=checkbox[] value='".$row['Customer_ID']."'></td>";
echo "<td><input type=hidden name =id value='".$row['Customer_ID']."' ></td>";
echo "<td><input type=text name= name value='".$row['Name_c']."'> </td>";
echo "<td><input type=text name=prenume value='".$row['Surname_c']."'> </td>";
echo "<td><input type=text name=brth value='".$row['brth']."'> </td>";
echo "<td><input type=text name=phone value='".$row['phone']."'> </td>";
echo "<td><input type=text name=adress value='".$row['adress']."'> </td>";
echo "<td><input type=text name=email value='".$row['email']."'> </td>";
echo "<td><input type=text name=serie value='".$row['series']."'> </td>";
echo "<td><input type=text name=type value='".$row['type']."'> </td>";
echo "<td><input type=text name=namei value='".$row['name_i']."'> </td>";
echo "<td><input type=text name=compn value='".$row['Company_N']."'> </td>";
echo "<td><input type=text name=value value='".$row['value']."'> </td>";
echo "<td><input type=text name=nr value='".$row['nr']."'> </td>";
echo "<td><input type=text name=entryin value='".$row['entry_d']."'> </td>";
echo "<td><input type=text name=entryout value='".$row['exp_d']."'> </td>";
echo "<td><input type=submit>";
echo "</form></tr>";
}
?>
</table>
</body>
</html>
答案 0 :(得分:0)
由于您的操作转到了display.php,我会假设您的第二页是&#39;是display.php。如果是这种情况,那么您需要使用$ _POST []。
检索提交的检查值在您的示例中,复选框命名为&#39;复选框&#39;所以你的POST应该如下所示......
<?php
$customer_id_arr = $_POST['checkbox'];
$customer_id_str = implode(",", $customer_id_arr);
//Connect to database
$connect=mysqli_connect("localhost" ,"root", "","asig");
//Select database
mysqli_select_db($connect,'asig');
//Select Query
$sql = "SELECT * FROM `customer`,`type`,`valability` WHERE customer.Customer_ID IN(" . $customer_id_str . ") AND valability.Insurance_ID=type.Insurance_ID";
//Execte query
$records=mysqli_query($connect,$sql);
?>
<html>
您的代码总体上需要一些工作/清理。
希望有所帮助。