php添加到数据库表,该怎么解决

WBOY
Release: 2016-06-13 12:01:51
Original
790 people have browsed it

php添加到数据库表
自学php,也看了一些解决的方法,但还是不行。遇到以下情况,不能成功向添加数据到数据库里,希望大神指点。这是我的表

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><br /><html xmlns="http://www.w3.org/1999/xhtml"><br /><head><br /><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><br /><title>无标题文档</title><br /></head><br /><body><br /><form method="POST"><br /><table><br /><tr><td>c_id</td><td><input type="c_id" size="20"></td></tr><br /><tr><td>c_name</td><td><input type="c_name" size="20"></td></tr><br /><tr><td>sector</td><td><input type="sector" size="50"></td></tr><br /><tr><td>e_address</td><td><input type="e_address" size="50"></td></tr><br /><tr><td>mail_address</td><td><input type="mail_address" size="50"></td></tr><br /><tr><td>classification</td><td><input type="classification" size="50"></td></tr><br /><tr><td>started_date</td><td><input type="started_date" size="50"></td></tr><br /><tr><td>contact</td><td><input type="contact" size="50"></td></tr><br /><tr><td>con_address</td><td><input type="con_address" size="50"></td></tr><br /><tr><td><input type="Submit" value="添加"></td></tr><br /></table><br /></form><br /><?php<br />$db = mysql_connect("localhost", "root", "root");<br />mysql_select_db("test", $db);<br />if(isset($_POST['submit'])&&$_POST['submit'])<br />{<br />     $sql="insert into customers_id(c_id,c_name,sector,e_address,mail_address,classification,started_date,contact,con_address) <br />     values('$_POST[c_id]','$_POST[c_name]','$_POST[sector]','$_POST[e_address]','$_POST[mail_address]','$_POST[classification]''$_POST[started_date]','$_POST[contact]','$_POST[con_address]''now()'";<br />     mysql_query($sql);<br />echo "成功";<br />}<br />?><br />echo "注册成功";<br /><br />?><br /><br /><br /><br /></body><br /></html>
Copy after login

------解决方案--------------------
1、表单控件的定义不对,都改成下面这样的:
   

2、提交按钮没有name值,不会进入if分支里面。
name="submit">

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