无法通过表单数据插入mysql数据库

时间:2015-04-24 06:15:05

标签: php mysql

我创建了一个表单,我想在提交值时插入mysql数据库,但是当我点击提交按钮时数据库没有更新..不知道我的代码在哪里出错..

Some Field I Dont Care About        = Nothing Interesting
Another Field That Doesnt Matter    = 216
Name                                = The_Job_name
More Useless Stuff                  = Blah blah
Estimated Completion                = Aug 13, 2015 13:30 EDT
Even Yet Still More Nonsense        = Exciting value
...

任何帮助?

-A

2 个答案:

答案 0 :(得分:5)

您在变量的使用中使用查询和缺少引号之间的额外括号,如下所示

$sql = "INSERT INTO `asset_inventory` (`server_name`,`ip_address`,`server_role`)
VALUES ('".$_POST['server_name']."','".$_POST['ip_address']."','".$_POST['server_role']."')";

答案 1 :(得分:0)

如果要插入字段 例如

你的sql将接受变量然后将其插入sql

$server_name = $_POST['server_name'];
$ip_address = $_POST['ip_address'];
$server_role = $_POST['server_role'];



 insert into  asset_inventory (server_name,ip_address,server_role) VALUES ('$server_name','$ip_address','$server_role';