0

Here is my query

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

Right now if I fill in all the forms so that there is no empty strings it gives me this error. The hash is $order_hash:

Unknown column '76a051b750ce9363cec3df9961d2fd6b' in 'field list'

If I leave some blank then it gives me:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' 1, , , , AL, , , , )' at line 27

I have tried multiple variations with double quotes, single quotes, etc and can't seem to figure it out. This should be a simple insert query that like I have done before but I just have run a muck with this one. Thanks for all of your help :)

4

1 回答 1

3

You need to write strings inside quote. Otherwise mysql will take them as column. For example:

...
'". $post_data['contact_first_name'] ."', 
'". $post_data['contact_last_name'] ."',
...

OR more simple (when using doublequote for query)

...
'{$post_data['contact_first_name']}', 
'{$post_data['contact_last_name']}',
...
于 2012-04-06T05:14:22.967 回答