插入数据
<?php
$name = $_GET['username'];
$sex = $_GET['sex'];
$hobby = $_GET['hobby'];
$address = $_GET['address'];
$remark = $_GET['remark'];
$conn = mysqli_connect("localhost","root","root","exercise");
if ($conn){
$sql = "INSERT INTO info(姓名,性别,爱好,家庭住址,备注) VALUES ('$name','$sex','$hobby','$address','$remark')";
if (mysqli_query($conn,$sql) === true) {
echo "新纪录插入成功";
} else {
echo "新剧路插入失败".mysqli_error($conn);
}
mysqli_close($conn);
}else{
die("连接数据库失败:" . mysqli_error());
}
?>
遍历表中所有数据
$conn = mysqli_connect("localhost","root","root","exercise");
if ($conn){
$result=mysqli_query($conn,"select * from info");
while($myrow=mysqli_fetch_row($result)) {
echo "<tr><td>$myrow[0]</td><td>$myrow[1]</td><td>$myrow[2]</td><td>$myrow[3]</td>
<td>$myrow[4]</td><td><a href='#'>修改</a> <a href='#'>删除</a></td></tr>";
}
mysqli_close($conn);
}else{
die("连接数据库失败:" . mysqli_error());
}