2017-06-24 26 views
1

更新ボタンを押すと、チェックボックスでチェックされたフィールドだけがリダイレクトされたページに表示されるため、私のコードに問題があります。チェックボックスの更新のみ

私は、最初のページからコードを、2番目のページからコードを、更新コードはウェブページのいくつかの写真に掲載します。

最初のページ:

firstpage

コードFIRSTPAGE:

<?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> 

画像、2ページ目:

secondpage

コード2ページ:

<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

あなたの行動はdisplay.phpに行くので、私はあなたの「第2ページ」はdisplay.phpであると仮定します。そうであれば、$ _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> 

...あなたのPOSTは以下のようになりますので、チェックボックスは、「チェックボックス」という名前されているあなたの例では。

希望に役立ちます。

+0

ありがとう!あなたの答えは便利でした! –

関連する問題