简体   繁体   English

插入表无法正常工作。 使用MySQL和PHP

[英]INSERT to table not working. Using MySQL and PHP

I have two scripts which insert a new line into my SQL database. 我有两个脚本,它们在SQL数据库中插入了新行。 One works, and the other doesn't. 一种有效,另一种无效。 They both look the same (but for the different data) but one doesn't work. 它们看起来都一样(但是用于不同的数据),但是不起作用。 I can not figure out what I am doing wrong. 我不知道我在做什么错。

Disclosure: I am self taught and have not taken any programming courses except for a pascal class several years ago. 披露:我是自学成才的,除了几年前的Pascal课外,没有参加任何编程课程。

This one works: include('db.php'); 这一项工作:include('db.php');

mysql_query("INSERT INTO leadprofile (first_name, last_name, home_phone, mobile_phone, work_phone, work_phone_ext, email_address, description, fk_source) VALUES ('$_POST[first_name]','$_POST[last_name]','$_POST[home_phone]','$_POST[mobile_phone]','$_POST[work_phone]','$_POST[work_phone_ext]','$_POST[email_address]','$_POST[description]','$_POST[fk_source]')");

mysql_close($con);

This one does not work. 这一项不起作用。 The page loads, but no values are inserted into the table: 该页面已加载,但表中未插入任何值:

include('db.php');

mysql_query("INSERT INTO tasks (fk_lead_id, task_type, task_detail, due_date) VALUES ('$_POST[fk_lead_id]',('$_POST[task_type]','$_POST[task_detail]','$_POST[due_date]')");

mysql_close($con);

Both are referencing the same db.php file which loads the database only. 两者都引用了仅加载数据库的同一个db.php文件。 I appreciate any help and hope it is something crazy simple. 我感谢任何帮助,希望这是一件疯狂的事情。 I have confirmed the table name and column names are all correct. 我已经确认表名和列名都是正确的。

Theres a bracket too much 支架太多

INSERT INTO tasks (fk_lead_id, task_type, task_detail, due_date)
    VALUES ('$_POST[fk_lead_id]',('$_POST[task_type]','$_POST[task_detail]','$_POST[due_date]')
                                 ^here

You would have easily found out if you had used mysql_error() eg like the following: 您将很容易发现是否使用了mysql_error()例如:

mysql_query("...") or die(mysql_error());

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM