我需要一个答案,为什么我不能在代码中显示变量或将数据插入数据库中, 首先是我需要插入,但是如果未插入,它不会显示错误代码,提交后,它只会刷新页面。我的插入人员有什么问题?或其他任何代码错误?
<?php
$con=mysqli_connect("localhost","root","","patient");
?>
<html>
<title>Patient record</title>
<head>
<style>
.align{
text-align:center;
}
</style>
</head>
<body>
<div class="align">
<form method="post">
<input name="patient" type="text" placeholder="Patient name" required/> <a href="edit.php?user="$_POST['id']">Edit</a> <a href="edit.php?user="$_POST['id']">Delete</a>
<br>
<br>
<input name="aphysician" type="text" placeholder="Admitting Physician" required/> <a href="edit.php?user="$_POST['id']">Edit</a> <a href="edit.php?user="$_POST['id']">Delete</a>
<br>
<br>
<input name="tphysician" type="text" placeholder="Treating Physician" required/> <a href="edit.php?user="$_POST['id']">Edit</a> <a href="edit.php?user="$_POST['id']">Delete</a>
<br>
<br>
Treatment:
<br>
<br>
<input name="time" type="text" placeholder="Date and time" required/> <a href="edit.php?user="$_POST['id']">Edit</a> <a href="edit.php?user="$_POST['id']">Delete</a>
<br>
<br>
<input name="result" type="text" placeholder="Result" required/> <a href="edit.php?user="$_POST['id']">Edit</a> <a href="edit.php?user="$_POST['id']">Delete</a>
<br>
<input type="submit" name="submit" value="Submit">
</form>
</div>
</body>
<?php
if(isset($POST['submit'])){
$patient=$_POST['patient'];
$aphysician=$_POST['aphysician'];
$tphysician=$_POST['tphysician'];
$time=$_POST['time'];
$result=$_POST['result'];
$q="INSERT INTO `details`(`patient`,`aphysician`,`tphysician`,`time`,`result`)VALUES
('".$patient."','".$aphysician."','".$tphysician."','".$time."','".$result."')";
$r=mysqli_query($con,$q);
if($r){
echo 'data inserted';
echo'<br><br>';
echo '"'.$patient.'" "'.$aphysician.'" "'.$tphyscician.'" "'.$time.'" "'.$result.'"';
echo'<br>';
}else{
echo $q;
}
}
?>
</html>
答案 0 :(得分:-1)
第1步。向表单标签添加操作
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
使您的表单提交到同一页面
第2步。提交后,您将使用
if($_SERVER["REQUEST_METHOD"] == "POST")
代替
if(isset($POST['submit']))