<form action="updata.php" method="post"> 姓名:<input type="text" value="" name="uname"> 年龄:<input type="text" value="" name="uage"> 属性:<input type="text" value="" name="ujob"> <input type="submit" value="提交"> </form>
<?php $name=$_POST['uname']; $age=$_POST['uage']; $job=$_POST['ujob']; $servername = "localhost"; $username = "root"; $password = "123456"; $dbname = "style"; // 创建连接 面向过程写法 $conn = mysqli_connect($servername, $username, $password, $dbname); // Check connection if (!$conn) { die("连接失败: " . mysqli_connect_error()); } mysqli_query($conn,'set names utf8');//设置字符集 $sql = "INSERT INTO ceshi(`name`, `age`,`job`) VALUES ('$name', '$age','$job')";//查询这个表 //判断是否成功 if (mysqli_query($conn, $sql)) { echo "New record created successfully"; } else { echo "Error: " . $sql . "<br>" . mysqli_error($conn); } mysqli_close($conn); ?>