0

I was inserting multiple arrays into my database using this code:

$queries_cols = array(); 

for($i=0; $i<count($cols); $i++) 
{ 
    $queries_cols [] = "('".$cols[$i]."','".$int_manha1_1[$i]."','".$int_manha1_2[$i]."','" .$int_tarde2_1[$i]."','".$int_tarde2_2[$i]."','".$h1_1[$i].$h1_2[$i]."','".$h2_1[$i].$h2_2[$i]."')" ; 
}

$query_col = "INSERT into cols_ponto_diaria values '".implode(",", $queries_cols)."'";

$result = mysql_query($query_col) or die("Erro: ".mysql_error());

And when I submit the form it output an error:

Erro: 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 ''('Ricardo','08:30:00','12:15:00','14:45:00','18:00:00','0115','1215')'' at line 1

Can anyone find where is the error? I've tried a few solutions but without any success.

Thanks in advance.

1
  • 1
    First port of call: Output the actual query that gets generated using echo $query_col;. Commented Jul 31, 2010 at 18:18

3 Answers 3

1

You could easily find it by printing $query_col as soon as you have it ready.

Anyway, the error I believe is in the implode() call. You don't need the extra quotes.

So instead of

$query_col = "INSERT into cols_ponto_diaria values '".implode(",", $queries_cols)."'";

try

$query_col = "INSERT into cols_ponto_diaria values ".implode(",", $queries_cols);
Sign up to request clarification or add additional context in comments.

1 Comment

Yeah, I got it. :) Thanks anyway.
1

Remove the single quote at the end of this expression,

INSERT into cols_ponto_diaria values 

Don't append the single quote at the end of the expression.

."'"

1 Comment

I saw your reply after I found the solution. Thank you Srinivas Reddy Thatiparthy.
0

Solution found. I tried several things and I forgot to try this approach. :(

Sorry for disturbing.

Here's the correct syntax:

$query_col = "INSERT into cols_ponto_diaria values ".implode(",", $queries_cols);

regards

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.