0

I have received this error while inserting data.

Error Number: 1064

You have an error in your SQL syntax; check the manual that corresponds to 
your MariaDB server version for the right syntax to use near '( [website] => 
[business_contact] => [business_landline] => ' at line 2

Following is the query.

     INSERT INTO `sp_business_details` (
        Array (
            [website] =>
            [business_contact] =>
            [business_landline] =>
            [state] => 1
            [state_name]=> Maharashtra
            [district] => 1
            [district_name] => Ahemadnagar
            [city] => 1
            [city_name] => Akole
            [pincode] => 425001
            [business_type] => 2
            [business_subtype] => 2
            [business_description] => A
            [address] => A
            [working_hrs_start] => 11:18 AM
            [working_hrs_end] => 11:18 AM
            [closed_day] => Sunday
            [registered_from] => 1
            [created_date] =>2018-04-18
        )
    ) VALUES ('');

I am using codeigniter $this->db->insert function. and passed the data array to this function

$q_businessdetails=$this->db->insert('sp_business_details',$sp_business_data);


var_dump($sp_business_data);o/p
string(686) "Array
(
[wbuser_id] => 153
[shop_name] => Moraya Computer Services
[shop_number] => 10
[website] => http://www.google.com
[business_contact] => 9403384505
[business_landline] => 2260676
[state] => 1
[state_name] => Maharashtra
[district] => 1
[district_name] => Ahemadnagar
[city] => 1
[city_name] => Akole
[pincode] => 425001
[business_type] => 1
[business_subtype] => 1
[business_description] => A
[address] => Adarsh Nagar Jalgaon
[working_hrs_start] => 11:18 AM
[working_hrs_end] => 11:18 AM
[closed_day] => Sunday
[registered_from] => 1
[created_date] => 2018-04-18

) "

2 Answers2

0

Error #1064 means that MySQL can't understand your command. To fix it:

Read the error message. It tells you exactly where in your command MySQL got confused.

Check the manual. By comparing against what MySQL expected at that point, the problem is often obvious.

Check for reserved words. If the error occurred on an object identifier, check that it isn't a reserved word (and, if it is, ensure that it's properly quoted).

For more information follow this link

0

The query you posted:

 INSERT INTO `sp_business_details` (
    Array (
        [website] =>
        [business_contact] =>
        [business_landline] =>

is not valid at all. $this->db->insert('table', $array); expects an array as the second parameter when you are giving it a string as denoted by your var_dump. I am not sure how you are writing the array but the proper syntax is:

$somearray = array('key' => 'value', 'key2' => 'value2');

it almost looks as if you are providing a print_r() as the second param. This is just a way of visualizing an array, not proper syntax for one.

Alex
  • 9,215
  • 8
  • 39
  • 82
  • See: `string(686)`. I don't know why... I don't see where/how you are writing your "array" - you haven't included that – Alex Apr 18 '18 at 07:09
  • actually i am creating a wizard form in codeigninter. so for that i fill first form data and submit it to the next form view here i am submitting this array as html form input value from the second form. I think this is where my array is being converted into string?? is that so?? – Vivek Deshpande Apr 18 '18 at 09:18
  • Possibly. Without the code I'd be purely speculating which isn't really helpful to anyone. The thing is a really array isn't defined like you have it with keys in brackets that's just a visual representation of an array. Which leads me to believe some weird stuff is going on. – Alex Apr 19 '18 at 03:06