0

So I get this error and I just can't understand why. In my opinion my syntax is correct, but it still doesn't work the way I want. Maybe I don't fully understand the mysql syntax in php

<?php
include 'db.php';

$data = array(
0 => array(
'comment_author_name' => 'Jurgis',
'comment_author_rank' => 'Pro',
'comment_date' => '2017-08-13 23:45:23',
'comment_message' => 'Lorem ipsum (trump. lipsum) yra tekstas naudojamas 
spaudos ir grafinio dizaino industrijoje jau nuo XVI amžiaus pradžios.'
),
1 => array(
'comment_author_name' => 'Martynas',
'comment_author_rank' => 'Newbie',
'comment_date' => '2017-08-14 13:32:15',
'comment_message' => 'Jis naudojamas parodyti grafinio pristatymo elementus, 
tokius kaip tipografija, dizainas ar šriftas.'
),
2 => array(
'comment_author_name' => 'Tomas',
'comment_author_rank' => 'Master',
'comment_date' => '2017-08-14 13:42:20',
'comment_message' => 'Jis taip pat kūrimo stadijoje naudojamas kaip kai 
kurių produktų aprašymų tekstas, prieš tai kai įrašomas tikrasis tekstas.'  
)
);



for($i=0; $i<count($data); $i++){
    $query = "INSERT INTO discussion_info 
    (comment_author_name,comment_author_rank,comment_date,comment_message)

          VALUES ('"$data[$i]['comment_author_name']"',
                  '"$data[$i]['comment_author_rank']"',
                  '"$data[$i]['comment_date']"',
                  '"$data[$i]['comment_message']"')";

    $mysqli_query($connection, $sql);   
}
?>
jverbys
  • 68
  • 7
  • You are not concatenating you variables correctly. It requires either `,` or `.` not just the variable. – Script47 Aug 14 '17 at 14:37

1 Answers1

0

You need to concat string with var data. Like this:

 VALUES ('" . $data[$i]['comment_author_name'] . "',
mitch
  • 2,235
  • 3
  • 27
  • 46