尝试更新无法从数据库获取数据的记录。获取空白页面无法从数据库获取任何数据。
<?php
include 'includes/db.php';
$id = (int)$_GET['appoint_id'];
$sql = "SELECT * FROM appointment WHERE appoint_id = '$id'";
$run = mysqli_query($conn,$sql);
while ($row = mysqli_fetch_assoc($run)){
$firstname = $row['first_name'];
$lastname = $row['last_name'];
}
?>
<form class="form-horizontal" action="update.php" method="post" role="form">
<input type='hidden' value='<?=$id;?>' name='appoint_id'>
<div class="body">
<div class="row clearfix">
<div class="col-sm-6 col-xs-12">
<div class="form-group">
<div class="form-line">
<input type="text" class="form-control" value="<?php echo $row['first_name'];?>" name="first_name" id="first_name" required>
</div>
</div>
</div>
<div class="col-sm-6 col-xs-12">
<div class="form-group">
<div class="form-line">
<input type="text" class="form-control" value="<?php echo $row['last_name'];?>" name="last_name" id="last_name" required>
</div>
</div>
</div>
</div>
</div>
</form>
update.php
<?php include 'includes/db.php';
if(isset($_POST['submit_user'])){
$ins_sql = "UPDATE first_name,last_name appointment WHERE appoint_id = '$id' ";
$run_sql = mysqli_query($conn,$ins_sql);
}else {
echo "not updated";
}
?>
也不会在错误日志中显示任何错误。
答案 0 :(得分:0)
update.php
的{{1}}查询语法不正确,并且它没有使用任何表单参数(表单参数中不存在的参数除外UPDATE
)。
您应该使用预准备语句来防止SQL注入。
$_POST['submit_user']
答案 1 :(得分:0)
?php session_start();
include 'includes/db.php';
$id = (int)$_GET['id'];
$sql = "SELECT * FROM appointment WHERE appoint_id = $id";
$oppointArr =array();
$result = mysqli_query($conn,$sql);
if (mysqli_num_rows($result) > 0) {
while($row = mysqli_fetch_array($result)) {
$oppointArr = $row;
echo "Name: " . $row["first_name"]. "<br>";
}
} else {
echo "0 results";
}
//mysqli_close($conn);
?>
查询获取特定记录的数据