php表单提交

WBOY
Release: 2016-06-23 14:31:37
Original
952 people have browsed it

不是第一次写表单提交了,但还是遇到了无法解决的问题。研究了将近一天,问了N多网友,最终解决了问题,过程颇为曲折。感谢大家的帮助。在此记录一下,以后不能在同一个地方摔倒了!

 数据库为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。内容为:

 include("conn.php");
if($_POST['submit']){
$sql="insert into test (id,name,sex) values ('','$_POST[name]','$_POST[sex]')";
mysql_query($sql); echo "成功!";
}

?>

 

     

之前的错误在哪?$_POST['submit']    $_POST[name]  记得要大写啊~~~

语法就是这样的吗?奇怪啊。还是先记住吧。以后会明白的。

需要注意的:1.$_POST[]一定要大写。无论在哪。

      2.提交的按钮一定要写上name和value.name="submit" value = “ ”

      3.action要提交到php文件

      4.解决页面中文乱码问题:在head里写删除,加上

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template