欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  php教程

php增删改查操作实例详解

程序员文章站 2022-05-17 20:26:00
...

1增 insert.php html head /head body form action="doinsert.php" method="POST" p ID:br/ input type="text" name="id" size="6" maxlength="6" / /p p 给自己起一个名号:br/ input type="text" name="name" size="10" maxlength="10" / /p p 给自己设一个

1增

insert.php







ID:




给自己起一个名号:




给自己设一个密码:




你的email地址:









doinsert.php


$linkID=@mysql_connect("localhost","root","123456");
if(!$linkID){
echo "没连接上";
}
$ss=@mysql_select_db("bean");
if(!$ss){
echo "没找到数据库";
}
$id = $_POST['id'];
$name = $_POST['name'];
$password = $_POST['password'];
$email = $_POST['email'];

$query = "INSERT INTO member3 (id,name,password,email) values(
'$id','$name','$password','$email')";
//$query = "insert into member3 set
// id='$id',name='$name',password='$password',email='$email'";

$result = mysql_query($query);

if($result) echo "

member successfuly insert!

";
else echo "

There was a problem inserting the member!

";

mysql_close();
include "insert.php" //返回并继续插入
?>

2查询并且修改

form.php










modify.php


$linkID=@mysql_connect("localhost","root","123456");
$ss=@mysql_select_db("bean");

$rowID = $_POST['rowID'];
$query="select id ,name,password,email from member3 where id='$rowID'";
$result=mysql_query($query);
if(!$result){
echo "没执行成功";
}
//echo "$result";


list($id,$name,$password,$email)=mysql_fetch_row($result);
//echo "$id";
//echo "$name";
//echo "$password";
//echo "$email";
mysql_close();
include "modifyform.php";

?>

modifyform.php








ID:

value="" />



你的名号:

value="" />



你的密码:

value="" />



你的邮箱:

value="" />







update.php

$linkID=@mysql_connect("localhost","root","123456");
$db=@mysql_select_db("bean");

$rowID=$_POST['rowID'];
$id=$_POST['id'];
$name=$_POST['name'];
$password=$_POST['password'];
$email=$_POST['email'];
//echo $rowID;
$query=" UPDATE member3 SET id='$id',name='$name',password='$password',email='$email'where id='$rowID' ";
//echo $query;
$result=mysql_query($query);

if($result) echo "

member successfuly update!

";
else echo "

There was a problem updating the member!

";

mysql_close();
?>

3删除 多选删除

deleteform.php 复选框






1 zcl

2 lv

3 ed

4 d





deleteform1.php 多选下拉列表











delete.php 遍历数组删除

$linkID=@mysql_connect("localhost","root","123456");
$db=@mysql_select_db("bean");
//echo $_POST['kk'];
//echo array('1','2','3');
foreach($_POST['kk'] as $pp)//遍历数组,给每个赋值
{
echo $pp;
$rowID=$pp;
$query="delete from member3 where id='$rowID'";//查询语句
$result=mysql_query($query);//放到数据库执行

if(!mysql_affected_rows()==0)
echo "

选择的项".$rowID."已经成功的被删除!

" ;

if(mysql_affected_rows()==0){
echo "

没有找到记录!

" ;
}
}


?>