-3
I’m having a terrible problem, I can’t update mysql via PDO, with array that comes from some form fields. I’ve tried a lot and so far I can’t update. The array comes in this format.
Array
(
[id] => Array
(
[0] => 1
[1] => 2
[2] => 3
[3] => 4
[4] => 5
[5] => 6
[6] => 7
[7] => 8
[8] => 9
[9] => 10
)
[url] => Array
(
[0] => /ckfinder/userfiles/images/2141.jpg
[1] => rty
[2] => rtyrcial.jpg
[3] => rtyrtrfiles/images/3.jpg
[4] => rtyrimages/especial.jpg
[5] => rtyrfiles/images/especial.jpg
[6] => rtyres/images/especial.jpg
[7] => /ckfinder/userfiles/images/3.jpg
[8] => /ckfinder/userfiles/images/Capa1.jpg
[9] => asd
)
)
TABLE (for example data):
SQL (PDO):
UPDATE via_imagens SET img_url = array[url] WHERE img_capa IS NULL AND img_id = array[id]
OK I’m passing like this:
$db = new PDO('mysql:host=localhost;dbname=test', 'root', '');
$sql = 'UPDATE via_imagens SET img_url = ? WHERE img_capa IS NULL AND img_id = ?';
$stmt = $db->prepare($sql);
foreach($dados as $item ){
$stmt->execute(array($dados['url'], $dados['id']));
}
But this mistake is coming: Notice: Array to string Conversion in, pointing to the line of $stmt->execute();
-1 by the title "help/urgent" and the unnecessary use of the high-end
– Guilherme Nascimento
What have you tried to do so far José? How is the excerpt of the code that is in trouble. I also recommend [Edit] your text. Read more at [Ask]
– gmsantos
I can’t loop both array[id] and array[url]. values into a single loop. To using foreach. And another, when I pass the value in array format to the PDO statement I get the Notice: Array to string Conversion.
– José Dam
I changed my answer.
– rray