我想更新alumni_request表中的数据。首先,它将显示数据,在它下面将是一个“批准”按钮。单击该按钮时,alu_request_status列将从0更新为1.以下是我的表单代码:
<?php
$data = "Select * from alumni_request";
$result = mysql_query($data) or die(mysql_error());
while($info = mysql_fetch_array( $result ))
{
$alu_request_id = $info['alu_request_id'] ;
$alu_request_description = $info['alu_request_description'] ;
$alu_request_date = $info['alu_request_date'] ;
$student_std_matric = $info['student_std_matric'] ;
?>
<div class="space-4"></div>
<p><label>Description:</label> <?php echo $alu_request_description; ?></p>
<p><label>Date:</label> <?php echo $alu_request_date; ?></p>
<p><label>By:</label> <?php echo $student_std_matric; ?></p>
<p>
<form action="admin-respond-alu-req-processor.php" method="post">
<button type="submit" class="btn btn-primary" name="alu_request_status" value="approve">Approve</button>
</form></p>
<hr>
<?php
}
?>
以下是admin-respond-alu-req-processor.php的代码
<?php
if(isset($_POST['approve']))
{
$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = '';
$conn = mysql_connect($dbhost, $dbuser, $dbpass);
if(! $conn )
{
die('Could not connect: ' . mysql_error());
}
$alu_request_id = $_POST['alu_request_id'];
$sql = "UPDATE alumni_request SET alu_request_status = 1 WHERE alu_request_id = $alu_request_id";
mysql_select_db('fskmkeda');
$retval = mysql_query( $sql, $conn );
if(! $retval )
{
die('Could not update data: ' . mysql_error());
}
echo "Updated data successfully\n";
mysql_close($conn);
}
else
{
header('Location: '."admin-respond-alu-req.php");
?>
<?php
}
?>
代码不起作用。我跟着这个网站做了一点改动:http://www.tutorialspoint.com/php/mysql_update_php.htm
请帮帮我:'(
答案 0 :(得分:1)
这是因为您需要使用:
if isset($_POST["alu_request_status"])
您正在使用$_POST['approve']