2017-05-29 114 views
1

编写代码以将我的mysql的结果回显到我的数据库表中之后,现在我试图让选定的行位于我的更新页面上,如显示一些信息桌子,以及能够同时更新表格使用php和mysqli从表中选择并更新表格

我对所有在线帮助感到困惑,我实际上已经阅读过其他内容来完成这项工作,但我相信我写了正确的代码,但可能只是错过某些我相信某些东西可以帮助我的东西。 这里的index.php从我的数据库

<?php 
//include auth.php file on all secure pages 
require("../db.php"); 
session_start(); 
if(!isset($_SESSION["username"])){ 
header("Location: login"); 
exit(); } 
?> 
<?php require_once('header.php')?> 

<div class="container content"> 


    <table id="myTable" class="table table-striped" > 
     <thead> 
      <tr> 
     <th>ConsignmentNo</th> 
     <th>Origin</th> 
     <th>Destination</th> 
     <th>PickupDate</th> 
     <th>Status</th> 
     <th >Actions</th> 
     </tr> 
     </thead> 
      <tbody> 
       <?php 
       $result = mysqli_query($con,"SELECT * FROM consignment"); 
       while($row = mysqli_fetch_array($result)) { 
        echo "<tr>"; 
       echo "<td>" . $row['consignmentno'] . "</td>"; 
       echo "<td>" . $row['shipmentorigin'] . "</td>"; 
       echo "<td>" . $row['shipmentdestination'] . "</td>"; 
       echo "<td>" . $row['shipmentpickupdate'] . "</td>"; 
       echo "<td>" . $row['shipmentstatus'] . "</td>"; 
       echo "<td><a name='consignmentno' href='update.php?id=".$row['consignmentno']."'>Edit</a></td>"; 
       echo "</tr>"; 
                } 
       mysqli_close($con); 
       ?> 
      </tbody> 
     </table> 
     </div> 






</div> 

<?php require_once('footer.php')?> 

显示表,这里是处理我的要求

<?php 
require("../db.php"); 
$track = $_GET['consignmentno']; 
$sql = "SELECT * FROM `consignment` WHERE consignmentno='$track'"; 
$result = $con->query($sql); 

if ($result->num_rows > 0) { 

    // output data of each row 
    while($row = $result->fetch_assoc()) { 

$consignmentno = $row['consignmentno']; 

$shippername = $row['shippername']; 

$shipperphone = $row['shipperphone']; 

$shipperaddress = $row['shipperaddress']; 

$shipperemail = $row['shipperemail']; 

$receivername = $row['receivername']; 

$receiverphone = $row['receiverphone']; 

$receiveraddress = $row['receiveraddress']; 

$receiveremail = $row['receiveremail']; 

$shipmenttype = $row['shipmenttype']; 

$shipmentweight = $row['shipmentweight']; 

$shipmentcourier = $row['shipmentcourier']; 

$shipmentpackage = $row['shipmentpackage']; 

$shipmentmode = $row['shipmentmode']; 

$shipmentproduct = $row['shipmentproduct']; 

$shipmentquantity = $row['shipmentquantity']; 

$shipmentfrieght = $row['shipmentfrieght']; 

$shipmentcarrier = $row['shipmentcarrier']; 

$departeddate = $row['departeddate']; 

$shipmentorigin = $row['shipmentorigin']; 

$shipmentdestination = $row['shipmentdestination']; 

$shipmentpickupdate = $row['shipmentpickupdate']; 

$shipmentstatus = $row['shipmentstatus']; 

$shipmentexpected = $row['shipmentexpected']; 

$comment = $row['comment']; 
    } 

} else { 
    echo "NO DETAILS FOR USER"; 
} 

$con->close(); 
?> 
<?php require_once('header.php')?> 

<div class="container content"> 
<script type="text/javascript"> 

$(document).ready(function(){ 


txt=$("#UpdateStatus").val(); 



if(txt=='3') 
{ 

$("#receive").slideDown("slow"); 

$("#UpdateReceivedBy").removeAttr("disabled"); 
} 
else 
{ 
$("#receive").slideUp("slow"); 
$('#UpdateReceivedBy').attr('disabled', 'true'); 

} 


    $("#UpdateStatus").change(function(){ 

     txt=$("#UpdateStatus").val(); 



if(txt=='3') 
{ 
$("#receive").slideDown("slow"); 
$("#UpdateReceivedBy").removeAttr("disabled"); 
} 
else 
{ 
$("#receive").slideUp("slow"); 
$('#UpdateReceivedBy').attr('disabled', 'true'); 

} 



    }); 
}); 

</script> 


<h2 class="col-md-offset-5">Update Shipment</h2> 





    <div class="row"> 
    <div class="table-responsive col-md-8 col-md-offset-2"> 

    <table class="table table-bordered table-hover"> 

    <thead> 
      <tr> 
      <th><h4><?php echo $consignmentno ; ?></h4> 

      </th> 

      <th> 

<h2>On Hold</h2>  
     </th> 

      </tr> 
     </thead> 

update.php页,但它不附和$consignmentno因为如果它可以这样做,那么其他事情变得更容易

这里是一个图像enter image description here,这表明我的索引页工作正常

所以请帮助我检查是否我得到了一切错误。由于

+1

您的代码容易受到SQL注入使用此代码。请学习使用[预先准备的语句](https://www.youtube.com/watch?v=nLinqtCfhKY)。 –

+1

$ track = $ _ GET ['id'],那是你的错误 –

+1

顺便说一句,你的代码容易受到sql注入的影响 –

回答

0

您必须update.php?consignmentno=line 35更换update.php?id=它能够解决您的问题

或者在的index.php

<?php 
//include auth.php file on all secure pages 
require("../db.php"); 
session_start(); 
if(!isset($_SESSION["username"])){ 
header("Location: login"); 
exit(); } 
?> 
<?php require_once('header.php')?> 

<div class="container content"> 


    <table id="myTable" class="table table-striped" > 
     <thead> 
      <tr> 
     <th>ConsignmentNo</th> 
     <th>Origin</th> 
     <th>Destination</th> 
     <th>PickupDate</th> 
     <th>Status</th> 
     <th >Actions</th> 
     </tr> 
     </thead> 
      <tbody> 
       <?php 
       $result = mysqli_query($con,"SELECT * FROM consignment"); 
       while($row = mysqli_fetch_array($result)) { 
        echo "<tr>"; 
       echo "<td>" . $row['consignmentno'] . "</td>"; 
       echo "<td>" . $row['shipmentorigin'] . "</td>"; 
       echo "<td>" . $row['shipmentdestination'] . "</td>"; 
       echo "<td>" . $row['shipmentpickupdate'] . "</td>"; 
       echo "<td>" . $row['shipmentstatus'] . "</td>"; 
       echo "<td><a name='consignmentno' href='update.php?consignmentno=".$row['consignmentno']."'>Edit</a></td>"; 
       echo "</tr>"; 
                } 
       mysqli_close($con); 
       ?> 
      </tbody> 
     </table> 
     </div> 
</div> 

<?php require_once('footer.php')?> 
+0

感谢@Rtra我从来没有注意到这行是最初的问题。 – phemieny7