Im trying to add multiple values from array in MySQL with one sql query but Im getting this error:
Notice: Array to string conversion in /var/www/index/test2.php on line 103 Warning: implode(): Argument must be an array in /var/www/index/test2.php on line 103
Here is code part where its wrong:
$sqlas = array();
foreach( $rezai as $rezas )
{
if (!empty($rezas)) {
$rezas = str_replace('http://', '', strip_tags($rezas));
}
else
{
$rezas = 'empty_rezas';
}
$failoID = explode('/', $rezas);
if (!isset($failoID[2]) || empty($failoID[2]))
{
$failoID[2] = 'neraID';
}
if (isset($rezas) && !empty($rezas))
{
$urlr = str_replace('www.mysite.com', '', $rezas);
}
$sqlas[] = '("'.mysqli_real_escape_string($conn, $failoID[2]).'", "'.mysqli_real_escape_string($conn, $urlr).'", "'.$uzklausaClean.'")';
}
$conn->query('INSERT INTO four_failai2 (id, url, uzklausa) VALUES '.implode(','. $sqlas).'');
$conn->close();
The line 103 is this one:
$conn->query('INSERT INTO four_failai2 (id, url, uzklausa) VALUES '.implode(','. $sqlas).'');
It says Argument must be an array, but I am defining $sqlas as empty array before foreach loop and then I am adding values inside loop. Any ideas?
You have a dot instead of a comma in your implode function.
Change implode(','. $sqlas)
to implode(',', $sqlas)
. As it is now, you're trying to concatenate the string containing the comma with an array (e.i. array to string conversion).