main页面(主页面)
die("连接失败"); } 代号 姓名 性别 民族 生日 操作
$db = new MySQLi("localhost","root","","mydb");
if(mysqli_connect_error()){
$sql = "select * from Info";
$result = $db->query($sql);
$attr = $result->fetch_all();
foreach($attr as $v)
{
$sex = $v[2]? '男':'女'; //三元运算符判断性别
$sql = "select Name from Nation where Code ='$v[3]'";
$result = $db ->query($sql);
$attr = $result->fetch_assoc();
echo " ";
{$v[0]}
{$v[1]}
{$sex}
{$attr['Name']}
{$v[4]}
删除
修改
}
?>
Add(添加数据页面)
添加数据
AddChuLi页面(添加数据处理页面)
$code = $_POST["code"];
$name = $_POST["name"];
$sex = $_POST["sex"];
$s = 1;
if($sex =="女")
{
$s=0;
}
$nation = $_POST["nation"];
$birthday = $_POST["birthday"];
$db = new MySQLi("localhost","root","","mydb");
if(mysqli_connect_error()){
die("连接失败");
}
$sql = "insert into Info values('{$code}','{$name}','{$s}','{$nation}','{$birthday}')"; //添加数据语句
$result = $db->query($sql);
if($result)
{
header("location:main.php"); //php跳转页面方式
}
else
{
echo "添加失败!";
}
DeleteChuLi页面(删除数据处理页面)
$code = $_GET["code"];
$db = new MySQLi("localhost","root","","mydb");
if(mysqli_connect_error()){
die("连接失败");
}
$sql = "delete from Info where Code ='{$code}'"; //删除语句
$r = $db->query($sql);
if($r)
{
header("location:main.php");
}
else
{
echo "删除失败!";
}
Update页面(修改数据页面)
修改数据
$code = $_GET["code"];
$db = new MySQLi("localhost","root","","mydb");
if(mysqli_connect_error()){
die("连接失败");
}
$sql1 = "select * from Info where Code='{$code}'";
$r1 = $db->query($sql1);
$att1 = $r1->fetch_row();
?>
UpdateChuLi页面(修改数据处理页面)
$code = $_POST["code"];
$name = $_POST["name"];
$sex = $_POST["sex"];
$s=1;
if($sex=="女")
{
$s=0;
}
$nation = $_POST["nation"];
$birthday = $_POST["birthday"];
$db = new MySQLi("localhost","root","","mydb");
if(mysqli_connect_error()){
die("连接失败");
}
$sql = "update Info set Name='{$name}',Sex={$s},Nation='{$nation}',Birthday='{$birthday}' where Code='{$code}'"; //修改数据语句
$r = $db->query($sql);
if($r)
{
header("location:main.php");
}
else
{
echo "修改失败!";
}