关于表单提交无法写入数据库

hubeiphp 2010-07-14 09:36:29
文章来源:http://www.phphubei.com/thread-297-1-1.html



关于表单提交无法写入数据库
//form.php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head>

<body>
<form action="insert.php" method="post" name="form1" id="form1">
<table width="300" border="0" align="center">
<tr>
<td>学号</td>
<td><label>
<input type="text" name="number" />
</label></td>
</tr>
<tr>
<td>姓名</td>
<td><input type="text" name="name" /></td>
</tr>
<tr>
<td>QQ</td>
<td><input type="text" name="qq" /></td>
</tr>
<tr>
<td>email</td>
<td><input type="text" name="email" /></td>
</tr>
<tr>
<td colspan="2"><label>
<div align="center">
<input type="submit" name="Submit" value="提交" />
</div>
</label></td>
</tr>
</table>
</form>
</body>
</html>


//insert.php

<?

$mysql_server_name = "localhost";
$mysql_username = "root";
$mysql_password = "";
$mysql_database = "cna";

$sql = "INSERT INTO `communication` ( `id` , `number` , `name` , `qq` , `email` , `time` )
VALUES (
'null', '$number', '$name', '$qq', '$email', NOW( )
);";

$conn=mysql_connect( $mysql_server_name, $mysql_username, $mysql_password);
mysql_select_db($mysql_database,$conn);
$result = mysql_query($sql);
$id = mysql_insert_id();
mysql_close($conn);

header("Location:form.php");
?>
在数据库中显示的是空白数据记录.请问这是怎么回事呢!谢谢!

...全文
36 点赞 收藏 4
写回复
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
max_soft 2010-07-14
汗。。。
回复
kyzy_yy_pm 2010-07-14
你都没$_POST数据能插入数据库么???????????????
回复
CunningBoy 2010-07-14
<?php
$mysql_server_name = "localhost";
$mysql_username = "root";
$mysql_password = "";
$mysql_database = "cna";

// 表单提交的数据在$_POST中
$number = $_POST['number'];
$name = $_POST['name'];
$qq = $_POST['qq'];
$email = $_POST['email'];

$sql = "INSERT INTO communication (id , number , name , qq , email , time)";
$sql .= "VALUES ('null', '$number', '$name', '$qq', '$email', NOW());";

$conn=mysql_connect( $mysql_server_name, $mysql_username, $mysql_password);
mysql_select_db($mysql_database,$conn);
$result = mysql_query($sql);
$id = mysql_insert_id();
mysql_close($conn);

header("Location:form.php");
?>
回复
max_soft 2010-07-14
$sql = "INSERT INTO `communication` ( `number` , `name` , `qq` , `email` , `time` )
VALUES (
'$number', '$name', '$qq', '$email', NOW( )
);";
id设为主键,auto_increment
回复
发动态
发帖子
基础编程
创建于2007-09-28

2.1w+

社区成员

从PHP安装配置,PHP入门,PHP基础到PHP应用
申请成为版主
社区公告
暂无公告