INSERT到表不起作用.使用MySQL和PHP


INSERT to table not working. Using MySQL and PHP

我有两个脚本,它们在SQL数据库中插入了一行新行。一个有效,另一个无效。它们看起来都一样(但数据不同),但其中一个不起作用。我不明白我做错了什么。

披露:我自学成才,除了几年前的pascal课程外,没有上过任何编程课程。

这个有效: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);

这个不起作用。页面加载,但没有值插入到表中:

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);

两者都引用了同一个只加载数据库的db.php文件。我很感激任何帮助,希望这是一件疯狂而简单的事情。我已经确认表名和列名都是正确的。

括号中太多

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

如果你使用了mysql_error(),你会很容易发现,例如:

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