首页 > 开发 > PHP > 正文

PHP学习笔记-数据库操作

2024-05-04 22:59:54
字体:
来源:转载
供稿:网友

<?php
$conn = mysql_connect("127.0.0.1","root","");  //连接mysql数据库
mysql_select_db("temp");  //选择数据库
$exec="select * from wind"; //选择数据表
$result = mysql_query($exec);  //执行记录
while ($rs=mysql_fetch_object($result))
{
 echo "姓名:".$rs->name."<br>";//等于rs.name
 echo "电话:".$rs->tel."<br>";
 echo "地址:".$rs->addr."<br><br>";
}
?>
<form method="post" action="day22.php">
用户名:<input type='text' name='name'><br>
电&nbsp;&nbsp;话:<input type='text' name='tel'><br>
地&nbsp;&nbsp;址:<input type='text' name='addr'><br>
<input type='submit' value='提交'><br><br>
</form>

 

========处理页

<?php
$conn = mysql_connect("127.0.0.1","root","");  //连接mysql数据库
mysql_select_db("temp");  //选择数据库
$sql = "insert into wind(name,tel,addr)values('".$_post['name']."','".$_post['tel']."','".$_post['addr']."')";
//删除,修改只需改$sql语句即可
//删除 $sql ="delete from wind where......"
//修改 $sql = "update wind set item1='".$_post['item1']."' where ...";
$rs1 = mysql_query($sql);
echo "数据插入成功!";
echo"<script>location.href('day2.php');</script>";
?>

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表