这是我的查询
// Put it all into the database
mysql_query("INSERT INTO
orders (
item_id,
order_id,
contact_first_name,
contact_last_name,
contact_email,
contact_phone,
business_name,
business_type,
business_website,
business_address,
business_city,
business_state,
business_zip,
business_phone,
promo_code,
add_details
)
VALUES(
". $post_data['item_id'] .",
". $order_hash .",
". $post_data['contact_first_name'] .",
". $post_data['contact_last_name'] .",
". $post_data['contact_email'] .",
". $post_data['contact_phone'] .",
". $post_data['business_name'] .",
". $post_data['business_type'] .",
". $post_data['business_website'] .",
". $post_data['business_address'] .",
". $post_data['business_city'] .",
". $post_data['business_state'] .",
". $post_data['business_zip'] .",
". $post_data['business_phone'] .",
". $post_data['promo_code'] .",
". $post_data['add_details'] ."
)
") or die(mysql_error());
现在,如果我填写所有表格,以便没有空字符串,它会给我这个错误。哈希是$ order_hash:
'字段列表'中的未知列'76a051b750ce9363cec3df9961d2fd6b'
如果我留下一些空白,那就给我:
您的SQL语法有错误;检查手册 对应于您的MySQL服务器版本,以便使用正确的语法 在第27行附近'1 ,,,, AL ,,,,)'
我尝试过双引号,单引号等多种变体,似乎无法弄明白。这应该是一个简单的插入查询,就像我之前所做的一样,但我只是运行了这个问题。感谢您的所有帮助:)
答案 0 :(得分:3)
你需要在引号内写字符串。否则mysql会将它们作为列。例如:
...
'". $post_data['contact_first_name'] ."',
'". $post_data['contact_last_name'] ."',
...
或更简单(当使用双引号进行查询时)
...
'{$post_data['contact_first_name']}',
'{$post_data['contact_last_name']}',
...