Clicking on the page will automatically input it to mysql. Solve
不愿
不愿 2020-12-16 08:55:55
0
3
1309

Trying to connect to mysql and enter data but without clicking submit, null values ​​will be uploaded. The following code is solved:

<!DOCTYPE html>
<html>
<head><meta charset="utf-8">
<title>input</title>
</head>
<body>
<?php
$lian= mysqli_connect('localhost','root','root','anu');//连接到anu
if($lian){
echo"连接数据库成功</br>";
}
else{
echo"连接数据库失败</br>";
}
?>
<form action="Draft2.php" method="post">
<div>姓名:<input type="text" name="name" required=""></div>
<div>就业意愿:<input type="text" name="job" required=""></div>
<div>电话:<input type="text" name="phone" required=""></div>
<input type="submit" name="1" value="保存"><!--create-->
<?php
$name = $_POST['name'];
$job = $_POST['job'];
$phone = $_POST['phone'];
$jia = "INSERT INTO draft VALUES('$name','$job','$phone')";
// if ($jia) {
// echo "添加成功·</br>";
// }
// else{
// echo "添加失败";
// }
mysqli_query($lian,$jia);
// or die(mysqli_error($lian));
mysqli_free_result($lian);
mysqli_close($lian)//断开数据库连接
?>
</form>
</body>
</html>

不愿
不愿

reply all(2)
星落

if($_POST){

Accept value and add database

}

西门大官人

Line 22 starts data writing. Just add an if judgment and don’t upload if there is no data

  • reply grateful
    不愿 author 2020-12-21 17:36:10
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template