我有一个表,它显示的一些请求用按钮来查看在一个单独的页面中选择请求的详细信息,如果用户是管理员的(approve)按钮将展示给他同意这个请求信息。下面是我的表的代码:

    }
    </style>
<body>
<h1 align="center">Table</h1>
<table border="5" align="center" style="line-height:20px;">
<tr>
<th>Request ID</th>
<th>Requester name</th>
<th>Customer name</th>
<th>Description</th>
<th>Submition Date</th>
<th>Request Status</th>
<th>link</th>
</tr>
<?php
// what the vp can view which can review all requests
if($_SESSION['dis'] == 'bvp')
{
    $req = "SELECT * FROM request_table where request_status='waiting for approver';";
    $request_table = $conn->query($req);
}
//what the b-team can only view which is everyone can only display his own requests
else if($_SESSION['dis'] == 'bteam')
{

    $req = "SELECT * FROM request_table where request_status='waiting for approver' AND requester = '$userin';";
    $request_table = $conn->query($req);

}

//Fetch Data form database
 if($request_table->num_rows > 0){
 while($view_request = $request_table->fetch_assoc()){
 ?>
 <tr>
 <td><?php echo $view_request['request_id']; ?></td>
 <td><?php echo $view_request['requester']; ?></td>
 <td><?php echo $view_request['customer_name']; ?></td>
 <td><?php echo "Site A is:". $view_request['site_a']. ",<br> Site B is: ".$view_request['site_b']. ",<br>NO. Of links =:".$view_request['no_oflinks']; ?></td>
 <td><?php echo $view_request['sub_date']; ?></td>
 <td><?php echo $view_request['request_status']; ?></td>
 <form action="view_request.php" method="GET"><td><button type="vieww" name="vieww" value= <?php echo $view_request['request_id']; ?>> View </button></td></form>
 </tr>
 <?php
 }
}

这里是查看请求页面的代码:


if(isset($_GET['vieww'])) 
{

 $view_r = $_GET['vieww'];
$view = "SELECT * FROM request_table WHERE request_id =$view_r";
    $vr = mysqli_query($conn,$view);

    while ($view_d = mysqli_fetch_assoc($vr))// get the data out from the result and put it inside the variable row as an array
{
    echo "Request id : ". $view_d['request_id']. "<br>";
    echo "Requester name is ". $view_d['requester']. "<br>";
    echo "customer name is ". $view_d['customer_name']. "<br>";// you can put number or name of the column inside incase of you want to show sepcific info like username or user
    echo "Site A is : ". $view_d['site_a']. ",<br>";
    echo "site B is : ". $view_d['site_b']. ",<br>";
    echo "bandwidth : ". $view_d['bandwidth']. ",<br>";
    echo "diversity : ". $view_d['diversity']. ",<br>";
    echo "latency : ". $view_d['latency']. ",<br>";
    echo "Protection : ". $view_d['protection']. ",<br>";
    echo "Number of Links : ". $view_d['no_oflinks']. ",<br>";
    echo "ECD is  : ". $view_d['ecd']. ",<br>";

}
}

if($_SESSION['dis'] == 'bvp'){
echo '<form action="includes/approve.inc.php" method = "GET"> <button type="submit" name="approved" value="approved">Approve</button> </form>';

}
//mysqli_close($conn);

?>

但它不工作,我不知道为什么我不能用我试图用变量做,但不工作一定请求ID更新我的数据库,所以上面的代码时,我只有串尝试。下面是我更新的代码:

    ?php

$servername ="localhost";
$dBUsername = "root";
$dBPassword = "";
$dBName = "loginsystem";

//$conn = new mysqli($servername,
//$dBUsername,$dBPassword,$dBName); //another server connection option like below

$conn = mysqli_connect($servername,$dBUsername,$dBPassword,$dBName); // this is the connection to our database

if(!$conn){

    die("connection faild:".mysqli_connect_error()); //send an error msg if connection failed
}




if(isset($_GET['approved']))
{
   // require 'dbh.inc.php';

//$approve="vbp approve";
$vpb_response="approved";
$vpb_response_date = date('Y-m-d');
$request_status = "waiting for TNS";
$request_status_date = date('Y-m-d');

$vpb_approve = "UPDATE request_table SET vpb_response = 'approved', vpb_response_date = '2019-10-29' , request_status = 'waiting for Tns', request_status_date = '2019-10-29',  WHERE request_id = '21';";

$resultch=mysqli_query($conn, $vpb_approve); // to just insert the above data and run it inside our db
if($resultch){
header("location:../r_table.php?success");
}
else {
    echo "error in updating";
}
}

希望你能帮我

分析解答

You have a comma before the WHERE clause which is causing the issue.

更改

"UPDATE request_table SET vpb_response = 'approved', vpb_response_date = '2019-10-29' 
, request_status = 'waiting for Tns', request_status_date = '2019-10-29'
, WHERE request_id = '21';"

"UPDATE request_table SET vpb_response = 'approved', vpb_response_date = '2019-10-29' 
 , request_status = 'waiting for Tns', request_status_date = '2019-10-29'
 WHERE request_id = '21';"