表单链接数据库,数据库该怎么设计,php连接程序怎么写?谢谢,下面是表单代码。
<body><formaction="Connection.php"method="post"><tablebgcolor="#eeeeee"><tr><tdcolspa...
<body>
<form action="Connection.php"method="post">
<table bgcolor="#eeeeee" >
<tr>
<td colspan="2" align="center"><b>情况登记</b>
<tr>
<td>姓名:<td><input size="20"type="text">
<tr>
<td>密码:<td><input size="20"type="password">
<tr>
<td>性别:<td><input type="radio" name="stuSex">男<input type="radio" vaule="stuSex">女
<tr>
<td><td><input type="submit" value="提交"></a><input type="reset"value="重写">
</table>
</form>
</body> 展开
<form action="Connection.php"method="post">
<table bgcolor="#eeeeee" >
<tr>
<td colspan="2" align="center"><b>情况登记</b>
<tr>
<td>姓名:<td><input size="20"type="text">
<tr>
<td>密码:<td><input size="20"type="password">
<tr>
<td>性别:<td><input type="radio" name="stuSex">男<input type="radio" vaule="stuSex">女
<tr>
<td><td><input type="submit" value="提交"></a><input type="reset"value="重写">
</table>
</form>
</body> 展开
1个回答
展开全部
网页:
<body>
<form action="Connection.php"method="post">
<table bgcolor="#eeeeee" >
<tr>
<td colspan="2" align="center"><b>情况登记</b>
<tr>
<td>姓名:<td><input size="20" type="text" name="name">
<tr>
<td>密码:<td><input size="20" type="password" name="password>
<tr>
<td>性别:<td><input type="radio" name="stuSex" value="0">男<input type="radio" name="stuSex" value="1">女
<tr>
<td><td><input type="submit" value="提交"></a><input type="reset"value="重写">
</table>
</form>
</body>
数据库表:
CREATE DATABASE `student`;
CREATE TABLE `student` (
`id` int(10) NOT NULL AUTO_INCREMENT,
`name` varchar(50) NOT NULL,
`password` varchar(50) NOT NULL,
`stusex` int(1) NOT NULL,
PRIMARY KEY (`id`)
);
PHP Connection.php代码:
<?php
$db = mysql_connect('localhost', 'root', '123456'); //root是数据库账号 123456 是数据库密码
if (!$db) {
die('无法连接: ' . mysql_error());
}
mysql_select_db('student', $db) or die ('无法使用数据库: ' . mysql_error());
$name = trim(strip_tags($_POST['name']));
$password = md5(trim($_POST['password']));
$stusex = intval($_POST['stusex']);
$sql = "insert into student (`name`,`password`,`stusex`) values ('$name','$password','$stusex')";
mysql_query($sql) or die("无法保存学生数据: " . mysql_error());
die("保存成功");
?>
<body>
<form action="Connection.php"method="post">
<table bgcolor="#eeeeee" >
<tr>
<td colspan="2" align="center"><b>情况登记</b>
<tr>
<td>姓名:<td><input size="20" type="text" name="name">
<tr>
<td>密码:<td><input size="20" type="password" name="password>
<tr>
<td>性别:<td><input type="radio" name="stuSex" value="0">男<input type="radio" name="stuSex" value="1">女
<tr>
<td><td><input type="submit" value="提交"></a><input type="reset"value="重写">
</table>
</form>
</body>
数据库表:
CREATE DATABASE `student`;
CREATE TABLE `student` (
`id` int(10) NOT NULL AUTO_INCREMENT,
`name` varchar(50) NOT NULL,
`password` varchar(50) NOT NULL,
`stusex` int(1) NOT NULL,
PRIMARY KEY (`id`)
);
PHP Connection.php代码:
<?php
$db = mysql_connect('localhost', 'root', '123456'); //root是数据库账号 123456 是数据库密码
if (!$db) {
die('无法连接: ' . mysql_error());
}
mysql_select_db('student', $db) or die ('无法使用数据库: ' . mysql_error());
$name = trim(strip_tags($_POST['name']));
$password = md5(trim($_POST['password']));
$stusex = intval($_POST['stusex']);
$sql = "insert into student (`name`,`password`,`stusex`) values ('$name','$password','$stusex')";
mysql_query($sql) or die("无法保存学生数据: " . mysql_error());
die("保存成功");
?>
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询