您的位置:首页 > 数据库

数据库操作

2016-06-27 18:27 295 查看
首先举一个示例吧!这里有一个学生表表格(用html),显示学生的基本信息,所以就得先从数据库中取出信息,这是对数据操作的前提,因为不取出信息,那你是对谁操作呢?

<!-- 请根据以下代码自己设计数据库 -->
/*connect.php*/

<?php

$conn=mysql_connect("localhost","root","root")  or die("数据库连接失败");

$select_db=mysql_select_db("test") or die("数据库选择失败");

mysql_query("set names utf8");//设置字符集
//注意顺序

$select_db="select *from stu order by stu_id";

$result=mysql_query($select_db);

if(!$result)


/*table.php*/
<html>
<head>
<title>table</title>
<meta charset="utf-8" />
</head>
<body>
<center>
<table width='30%' align='center' border='1'>
<tr>
<td colspan='6' align='left'><a href='insert.php'><input name="return" type="button" value="添加" ></a></a></td>
</tr>
<tr>
<td colspan='6' align='center'>学生信息表</td>
</tr>
<tr bgcolor='pink'>
<td>编号</td>
<td>姓名</td>
<td>年龄</td>
<td>性别</td>
<td colspan=2 align='center'>操作</td>
</tr>

<?php
include("connect.php");	//包含数据连接

while($row=mysql_fetch_array($result))
{
?>
<tr>
     
<td><?php echo $row['stu_id'];?></td>
<td><a href='show.php?ud=<?php echo $row["stu_id"];?>'><?php echo $row['stu_name'];?></a></td>
<td><?php echo $row['stu_age'];?></td>
<td><?php echo $row['stu_sex'];?></td>
<td align='center'><a href='edit.php?ud=<?php echo $row["stu_id"];?>'><input name="return" type="button" value="编辑" ></a></td>
<td align='center'><a href='delete.php?ud=<?php echo $row["stu_id"];?>'><input name="return" type="button" value="删除" ></a></td>
</tr>

<?php
}
?>
</table>
<?php
mysql_close($conn);   //关闭数据库
?>
</center>
</body>
</html>

以上两个代码实现显示信息


{ echo 'SQL语句操作失败'; mysql_error(); } ?>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: