-3

Helo! I'm trying to execute a mysql query but I've ran into the problem above.

This is my code:

$query = ("UPDATE cegek SET CegNev='".$cegnev."', Kozpont='".$kozpont."', Bevetel='".$bevetel."', Alkalmazottak='".$alkalmazott."', Iparag='".$iparag."' WHERE id=".$id."'");
$conn = $db->prepare($query);
$conn->bind_param("ssiisi", $cegnev, $kozpont, $bevetel, $alkalmazott, $iparag, $id);
$db->close();

And it's result is:

Fatal error: Call to a member function bind_param() on boolean in...

I have found some similar questions but I couldn't figure out the solution. Anyone can help me?

1 Answers1

1

You should use following syntax:

$stmt = $mysqli->prepare("INSERT INTO CountryLanguage VALUES (?, ?, ?, ?)");
$stmt->bind_param('sssd', $code, $language, $official, $percent);

So in your code it will be like:

$conn = $db->prepare('INSERT INTO Table VALUES (?, ?, ?, ?, ?, ?)');
$conn->bind_param("ssiisi", $cegnev, $kozpont, $bevetel, $alkalmazott, $iparag, $id);

Also it can return boolean (false) if there is error in your query (f.ex. wrong table name).

Karol Gasienica
  • 2,665
  • 21
  • 33
  • Still can't get it to work. My query is: $query = ("UPDATE cegek SET CegNev='".$cegnev."', Kozpont='".$kozpont."', Bevetel='".$bevetel."', Alkalmazottak='".$alkalmazott."', Iparag='".$iparag."' WHERE id=".$id."'"); – TheyCallMeSont Nov 21 '16 at 18:16
  • You are binding params so in place of variable in `$query` you should put `?`. – Karol Gasienica Nov 21 '16 at 18:17
  • Try: `"UPDATE cegek SET CegNev='?', Kozpont='?', Bevetel='?', Alkalmazottak='?', Iparag='?' WHERE id='?'"` – Karol Gasienica Nov 21 '16 at 18:18