用php做 mysql 一张表的 增、删、改、查。

phpmysql一张表的增、删、改、查。表学号姓名院系专业班级发到邮箱:sharestudio@126.com最好附上.sql文件谢谢... php mysql 一张表的 增、删、改、查。
表 学号 姓名 院系 专业 班级
发到邮箱:sharestudio@126.com
最好附上 .sql文件
谢谢
展开
 我来答
匿名用户
2012-06-19
展开全部
<?php
$link=mysql_connect("localhost","root","123456")
or die("数据库服务器连接失败!<BR>");
mysql_query("CREATE DATABASE student",$link)
or die("数据库student创建失败!<BR>");
echo "数据库student创建成功!<BR>";
mysql_select_db("student",$link)
or die("数据库student选择失败!<BR>");
echo "数据库student选择成功!<BR>";
//创建表t_student
$sql="CREATE TABLE t_student(xh CHAR(11) NOT NULL,";
$sql.="xm VARCHAR(12) NOT NULL,xb CHAR(2) NOT NULL,";
$sql.="bjdm CHAR(9) NOT NULL,csrq DATE,";
$sql.="PRIMARY KEY(xh))";
$sql.="ENGINE=MyISAM DEFAULT CHARSET=gb2312";
mysql_query($sql,$link) or die("表t_student创建失败!<BR>");
echo "表t_student创建成功!<BR>";
//创建表t_class
$sql="CREATE TABLE t_class(bjdm CHAR(9) NOT NULL,";
$sql.="bjjc VARCHAR(15) NOT NULL,bjqc VARCHAR(30) NOT NULL,";
$sql.="PRIMARY KEY(bjdm))";
$sql.="ENGINE=MyISAM DEFAULT CHARSET=gb2312";
mysql_query($sql,$link) or die("表t_class创建失败!<BR>");
echo "表t_class创建成功!<BR>";
$sql="ALTER TABLE t_class ADD bj CHAR(3) NOT NULL";
mysql_query($sql,$link) or die("字段添加失败!<BR>");
//在表t_class中修改字段bj
$sql="ALTER TABLE t_class CHANGE bj bj CHAR(5) NOT NULL";
mysql_query($sql,$link) or die("字段修改失败!<BR>");
//在表t_class中删除字段bj
$sql="ALTER TABLE t_class DROP bj";
mysql_query($sql,$link) or die("字段删除失败!<BR>");
echo "表t_class修改成功!<BR>";
$sql="select bjdm,bjjc,bjqc from t_class where bjdm='200501011'";
$result=mysql_query($sql,$link);
$row = mysql_fetch_array($result);
//$row = mysql_fetch_row($result);
//$row = mysql_fetch_assoc($result);
if (!$row) {
echo "无此班级代码!";
die();
}
$bjdm=$row['bjdm'];
$bjjc=$row['bjjc'];
$bjqc=$row['bjqc'];
echo "班级代码:".$bjdm."<BR>";
echo "班级简称:".$bjjc."<BR>";
echo "班级全称:".$bjqc."<BR>";
$sql="insert into t_class(bjdm,bjjc,bjqc)";
$sql=$sql." values('2006','计1','计算机1班')";
if (mysql_query($sql,$link))
echo "班级增加成功!";
else
echo '班级增加失败!';
$sql="delete from t_class where bjdm='2006');
mysql_query($sql,$link);
$sql="DROP TABLE t_class";
mysql_query($sql,$link) or die("表t_class删除失败!<BR>");
echo "表t_class删除成功!<BR>";
duan2010169
2012-06-22
知道答主
回答量:15
采纳率:0%
帮助的人:7.4万
展开全部
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>
给自己设一个密码:<br/>
<input type="password" name="password" size="8" maxlength="8" value=""/>
</p>
<p>
你的email地址:<br/>
<input type="text" name="email" size="20" maxlength="20" value=""/>
</p>
<p>
<input type="submit" name="submit" value="Submit!"/>
</p>
</form>
</body>
</html>

doinsert.php

<?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 "<p>member successfuly insert!</p>";
else echo "<p>There was a problem inserting the member!</p>";

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

2查询并且修改

form.php

<html>
<head>
</head>
<body>
<form action="modify.php" method="post">
<select name="rowID">
<option value="">choose a ID:</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
<input type="submit" name = "submit" value="Submit!"/>
</form>
</body>
</html>

modify.php

<?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

<html>
<head>
</head>
<body>
<form action="update.php" method="POST">
<input type="hidden" name="rowID" value="<?php echo $rowID;?>">
<p>
ID:<br/>
<input type="text" name="id" size="6" maxlength="6"
value="<?php echo $id; ?>" />
</p>
<p>
你的名号:<br/>
<input type="text" name="name" size="10" maxlength="10"
value="<?php echo $name; ?>" />
</p>
<p>
你的密码:<br/>
<input type="password" name="password" size="8" maxlength="8"
value="<?php echo $password; ?>" />
</p>
<p>
你的邮箱:<br/>
<input type="text" name="email" size="20" maxlength="20"
value="<?php echo $email; ?>" />
</p>
<p>
<input type="submit" name="submit" value="Submit!"/>
</p>
</form>
</body>
</html>

update.php

<?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 "<p>member successfuly update!</p>";
else echo "<p>There was a problem updating the member!</p>";

mysql_close();
?>

3删除 多选删除

deleteform.php 复选框

<html>
<head>
</head>
<body>
<form action="delete.php" method="post">
<input type="checkbox" name="kk[]" value="1" />1 zcl<br/>
<input type="checkbox" name="kk[]" value="2" />2 lv<br/>
<input type="checkbox" name="kk[]" value="3" />3 ed<br/>
<input type="checkbox" name="kk[]" value="4" />4 d<br/>

<input type="submit" name = "submit" value="Submit!"/>
</form>
</body>
</html>

deleteform1.php 多选下拉列表

<html>
<head>
</head>
<body>
<form action="delete.php" method="post">
<select name="kk[]" multiple="multiple">
<option value="">choose a ID:</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
<input type="submit" name = "submit" value="Submit!"/>
</form>
</body>
</html>

delete.php 遍历数组删除

<?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 "<p>选择的项".$rowID."已经成功的被删除!</p>" ;

if(mysql_affected_rows()==0){
echo "<p>没有找到记录!</p>" ;
}
}
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式