php连接数据库开发实例

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gbk" />
<title>学生基本信息管理系统</title>
</head>
<body>
<h2>学生基本信息管理系统</h2>
	<h3>学生管理</h3>
	<a href="insertS.html">添加学生信息</a>
	<a href="seekS.html">查看学生信息</a>
	<a href="deleteS.html">删除学生信息</a>
	<h3>管理员管理</h3><br>
	<a href="admin_add.html">添加管理员</a>
	<a href="admin_cheak.html">查看管理员</a>
</body>
</html>
<?php
$con=mysqli_connect("localhost:3306","root","bwcx130313");
if (!mysqli_select_db($con,"student")) {
	echo "连接失败".mysqli_connect_error();
	exit;
}
else echo"连接成功";
mysqli_query($con,"set names utf8");
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gbk" />
<title>添加学生信息</title>
</head>
<body>
<h3>添加学生信息</h3>
<form name="insertS" method="post"action='insertS.php'>&nbsp &nbsp&nbsp&nbsp&nbsp&nbsp号:<input type="text"name="stuid"><br>&nbsp &nbsp&nbsp&nbsp&nbsp&nbsp名:<input type="text"name="stuname"><br>&nbsp &nbsp&nbsp&nbsp&nbsp&nbsp别:<input type="text"name="stusex"><br>
出生年月:<input type="text"name="stubirth"><br>&nbsp &nbsp&nbsp&nbsp&nbsp&nbsp系:<input type="text"name="stuschool"><br>
		<input type="submit" name="submit" value="提交" />
</from>
</body>
</html>
<?php
$con=mysqli_connect("localhost:3306","root","bwcx130313");
if (!mysqli_select_db($con,"student")) {
	echo "连接失败".mysqli_connect_error();
	exit;
}
else echo"连接成功";
mysqli_query($con,"set names utf8");
$stuid=$_POST["stuid"];
$stuname=$_POST["stuname"];
$stusex=$_POST["stusex"];
$stubirth=$_POST["stubirth"];
$stuschool=$_POST["stuschool"];
$sql="insert into stu values('$stuid','$stuname','$stusex','$stubirth','$stuschool')";
if (mysqli_query($con,$sql))
echo "添加成功";
else echo "添加失败";
mysqli_close($con);
?>
<?php
<?php
$con=mysqli_connect("localhost:3306","root","bwcx130313");
if (!mysqli_select_db($con,"student")) {
	echo "连接失败".mysqli_connect_error();
	exit;
}
else echo"连接成功";
mysqli_query($con,"set names utf8");
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gbk" />
<title>查看学生信息</title>
</head>
<body>
<h3>查看学生信息</h3>
<form name="seekS" method="post"action='seekS.php'>&nbsp &nbsp&nbsp&nbsp&nbsp&nbsp号:<input type="text"name="stuid"><br>
		<input type="submit" name="submit" value="提交" />
</from>
</body>
</html>
?>
<?php
$con=mysqli_connect("localhost:3306","root","bwcx130313");
if (!mysqli_select_db($con,"student")) {
	echo "连接失败".mysqli_connect_error();
	exit;
}
else echo"连接成功";
mysqli_query($con,"set names utf8");
$q="select stuid,stuname,stusex,stubirth,stuschool from stu where stuID=1805004425";
$result = mysqli_query($con,$q);
if ($result) {
	echo "信息查询成功<br>";
	$p=mysqli_fetch_array($result,MYSQLI_BOTH);
	if ($p) {
	echo "stuid:.".$p[0]."<br>";
	echo "stuname:".$p[1]."<br>";
	echo "stusex:.".$p[2]."<br>";
	echo "stubirth:".$p[3]."<br>";
	echo "stuschool:".$p[4]."<br>";
}
else {
	echo "信息不存在";
}


}
else {
	echo "信息查询失败";
}

?>

<?php
$con=mysqli_connect("localhost:3306","root","bwcx130313");
if (!mysqli_select_db($con,"student")) {
	echo "连接失败".mysqli_connect_error();
	exit;
}
else echo"连接成功";
mysqli_query($con,"set names utf8");
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gbk" />
<title>删除学生信息</title>
</head>
<body>
<h3>删除学生信息</h3>
<form name="seekS" method="post"action='deleteS.php'>&nbsp &nbsp&nbsp&nbsp&nbsp&nbsp号:<input type="text"name="stuid"><br>
		<input type="submit" name="submit" value="提交" />
</from>
</body>
</html>
<?php
$con=mysqli_connect("localhost:3306","root","bwcx130313");
if (!mysqli_select_db($con,"student")) {
	echo "连接失败".mysqli_connect_error();
	exit;
}
else echo"连接成功";
mysqli_query($con,"set names utf8");
$stuid=$_POST["stuid"];
$q="delete from stu  where stuid='$stuid'";
if (mysqli_query($con,$q)) {
	echo "修改成功";
}
else {
    echo "修改失败";
}
?>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值