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

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");
?>
在数据库中显示的是空白数据记录.请问这是怎么回事呢!谢谢!

...全文
121 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
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

21,887

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧