php表单提交问题的解决方法

yipeiwu_com6年前PHP代码库
在此记录一下,以后不能在同一个地方摔倒了!
数据库为bbs,表为test.三个字段,分别为id,name,sex。id为auto_increment。
连接数据库的php文件conn.php内容为
复制代码 代码如下:

$conn = @ mysql_connect("localhost", "root", "") or die("数据库链接错误");
mysql_select_db("bbs", $conn);
mysql_query("set names 'GBK'"); //使用GBK中文编码;

表单页:add2.php。内容为:
复制代码 代码如下:

<?php
include("conn.php");
if($_POST['submit']){
$sql="insert into test (id,name,sex) values ('','$_POST[name]','$_POST[sex]')";
mysql_query($sql); echo "成功!";
}
?>
<form action="add2.php" method="post">
<input type="text" name="name" value="输入名字" />
<input type="text" name="sex" value="输入性别" />
<input type="submit" name="submit" value="提交" />
</form>

之前的错误在哪?$_POST['submit'] $_POST[name] 记得要大写啊~~~
语法就是这样的吗?奇怪啊。还是先记住吧。以后会明白的。
需要注意的:1.$_POST[]一定要大写。无论在哪。
      2.提交的按钮一定要写上name和value.name="submit" value = “ ”
      3.action要提交到php文件
      4.解决页面中文乱码问题:在head里写删除<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />,加上<meta http-equiv="Content-Type" content="text/html; charset=gb2312">

相关文章

用php或asp创建网页桌面快捷方式的代码

用php或asp创建网页桌面快捷方式的代码

新建一个PHP文档:名字好记就行如:shortcut.php PHP文档中的内容: 代码 复制代码 代码如下: <?php $Shortcut = "[InternetShortc...

php中调用其他系统http接口的方法说明

使用函数:  file_get_contents($url); 传入接口url及其参数:如 $url="http://192.168.1.1/test.jsp?id=1&typ...

PHP中file_exists与is_file,is_dir的区别介绍

很显然file_exists是受了asp的影响,因为asp不但有fileExists还有folderExists,driverExists,那么PHP中file_exists是什么意思呢...

PHP获取汉字笔画数功能【测试可用】

本文实例讲述了PHP获取汉字笔画数功能。分享给大家供大家参考,具体如下: 无意中看到这么个东西,用PHP得到汉字的笔画数。以类的方式实现,有那么点意思,先留下了。 <?...

关于shopex同步ucenter的redirect问题,导致script不运行

首先此问题来自向这个帖子 http://hi.baidu.com/fire_love_live/item/247276cfda421217b67a24c7 需要说明的是,并非15处需要修...