prepare update statement met array waarden voor kolommen
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
foreach ($content as $productId)
{
foreach ($fieldArr as $value )
{
if (isset($_GET[$value]) && $_GET[$value] != '')
{
echo $productId.'<br/>';
$inn = $DBD->conn()->prepare('UPDATE producten SET "'.$value.'" = ? WHERE id = ?');
$inn->bind_param( "ss",$_GET[''.$value.''],$productId);
if (!$inn->execute())
{
$error = $inn->error;
echo $error;
$inn->close();die();
}
}
} // end foreach
} // end foreach
{
foreach ($fieldArr as $value )
{
if (isset($_GET[$value]) && $_GET[$value] != '')
{
echo $productId.'<br/>';
$inn = $DBD->conn()->prepare('UPDATE producten SET "'.$value.'" = ? WHERE id = ?');
$inn->bind_param( "ss",$_GET[''.$value.''],$productId);
if (!$inn->execute())
{
$error = $inn->error;
echo $error;
$inn->close();die();
}
}
} // end foreach
} // end foreach
Ik krijg deze foutmelding:
Fatal error: Uncaught Error: Call to a member function bind_param() on boolean in...
Is dit op te lossen?
Doe het met of zonder ` en dan consequent :
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
<?php
foreach ($content as $productId) {
foreach ($fieldArr as $value) {
if ( ! empty($_GET[$value])) {
echo $productId . '<br/>';
$sql = "UPDATE producten SET {$value} = ? WHERE id = ?";
$inn = $DBD->conn()->prepare($sql);
if (false === $inn) {
printf('<pre>Invalid query: %s</pre>', $sql);
} else {
$inn->bind_param("ss", $_GET[$value], $productId);
if ( ! $inn->execute()) {
$error = $inn->error;
echo $error;
$inn->close();die();
}
}
}
}
}
?>
foreach ($content as $productId) {
foreach ($fieldArr as $value) {
if ( ! empty($_GET[$value])) {
echo $productId . '<br/>';
$sql = "UPDATE producten SET {$value} = ? WHERE id = ?";
$inn = $DBD->conn()->prepare($sql);
if (false === $inn) {
printf('<pre>Invalid query: %s</pre>', $sql);
} else {
$inn->bind_param("ss", $_GET[$value], $productId);
if ( ! $inn->execute()) {
$error = $inn->error;
echo $error;
$inn->close();die();
}
}
}
}
}
?>
Gewijzigd op 15/06/2022 19:48:10 door Jan Koehoorn