<h1>主页面family</h1>
<table width="100%" border="1px" cellpadding="0" cellspacing="0" >
<tr>
<td>ID</td>
<td>INFOCODE</td>
<td>NAME</td>
<td>TITLE</td>
<td>FIRM</td>
<td>ORDERS</td>
<td width="80" >UPDATE</td>
<td width="80" >DELETE</td>
</tr>
<?PHP
//造连接对象
$fam = new MySQLi("localhost","root","","zw");
//判断是否连接
!mysqli_connect_error() or die("连接失败");
//写SQL语句
$sql="select * from family";
//执行语句
$result = $fam->query($sql);
//取数据
$attr = $result->fetch_all();
foreach($attr as $v)
{
//关系名称
$sql2="select Name from title where Code='{$v[3]}'";
$rname=$fam->query($sql2);
$attn=$rname->fetch_row();
echo "<tr>
<td>{$v[0]}</td>
<td>{$v[1]}</td>
<td>{$v[2]}</td>
<td>{$attn[0]}</td>
<td>{$v[4]}</td>
<td>{$v[5]}</td>
<td align='center'><a href='Update.php?Ids={$v[0]}'>更改</a></td>
<td align='center'><a href='Delete.php?Ids={$v[0]}'>删除</a></td>
</tr>";
}
?>
</table>
<div><a href="Add.php">添加数据</a></div>
添加页面
<h1>添加数据</h1>
<form action="AddChuLi.php" method="post">
Ids:<div><input type="text" name="Ids" /></div>
代号:<div><input type="text" name="Infocode" /></div>
姓名:<div><input type="text" name="Name" /></div>
关系:<div>
<select name="gx">
<?php
$fam=new MySQLi("localhost","root","","zw");
!mysqli_connect_error() or die("失败");
$sql="select * from title";
$r=$fam->query($sql);
$attr=$r->fetch_all();
foreach($attr as $v)
{
echo "<option value='{$v[0]}'>{$v[1]}</option>";
}
?>
</select>
</div>
工作单位:<div><input type="text" name="Firm" /></div>
Orders:<div><input type="text" name="Orders" /></div>
<div><input type="submit" value="提交" /></div>
</form>
<div><a href="main.php">主页面</a></div>
纯PHP 添加处理页面
<?php
$Ids=$_POST["Ids"];
$Infocode=$_POST["Infocode"];
$Name=$_POST["Name"];
$Title=$_POST["gx"];
$Firm=$_POST["Firm"];
$Orders=$_POST["Orders"];
$fam=new MySQLi("localhost","root","","zw");
!mysqli_connect_error() or die("连接失败!");
$sql="insert into family values('{$Ids}','{$Infocode}','{$Name}','{$Title}','{$Firm}','{$Orders}')";
$result=$fam->query($sql);
if($result)
{
header("location:Add.php");
}
else
{
echo "添加失败";
}
修改页面
<h1>修改数据</h1>
<?php
$Ids=$_GET["Ids"];
$fam=new MySQLi("localhost","root","","zw");
!mysqli_connect_error() or die("失败");
$sql1="select * from family where Ids={$Ids}";
$r=$fam->query($sql1);
$att=$r->fetch_row();
?>
<form action="UpdateChuLi.php" method="post">
Ids:<div><input readonly="readonly" type="text" name="Ids" value="<?php echo $att[0] ?>"/></div>
代号:<div><input readonly="readonly" type="text" name="Infocode" value="<?php echo $att[1] ?>" /></div>
姓名:<div><input type="text" name="Name" value="<?php echo $att[2] ?>" /></div>
关系:<div>
<select name="gx">
<?php
$sql="select * from title";
$r=$fam->query($sql);
$attr=$r->fetch_all();
foreach($attr as $v)
{
if($v[0]==$att[3])
{
echo "<option selected='selected' value='{$v[0]}'>{$v[1]}</option>";
}
else
{
echo "<option value='{$v[0]}'>{$v[1]}</option>";
}
}
?>
</select>
</div>
工作单位:<div><input type="text" name="Firm" value="<?php echo $att[4] ?>" /></div>
Orders:<div><input type="text" name="Orders" value="<?php echo $att[5] ?>"/></div>
<div><input type="submit" value="提交" /></div>
</form>
<div><a href="main.php">主页面</a></div>
纯PHP 修改处理页面
<?php
$Ids=$_POST["Ids"];
$Infocode=$_POST["Infocode"];
$Name=$_POST["Name"];
$Title=$_POST["Title"];
$Firm=$_POST["Firm"];
$Orders=$_POST["Orders"];
$fam=new MySQLi("localhost","root","","zw");
!mysqli_connect_error() or die("连接失败!");
$sql="Update family set Name='{$Name}',Title='{$Title}',Firm='{$Firm}',Orders='{$Orders}'where Ids='{$Ids}'";
$result=$fam->query($sql);
if($result)
{
header("location:main.php");
}
else
{
echo "失败";
}
纯PHP 修改处理页面
<?php
$Ids=$_GET["Ids"];
$fam=new MySQLi("localhost","root","","zw");
!mysqli_connect_error() or die("失败");
$sql="delete from family where Ids={$Ids}";
$r=$fam->query($sql);
if($r)
{
header("location:main.php");
}
else
{
echo "删除失败";
}