I have two subsequent mysqli statements, and the second returns:
Fatal error: call of bind_param () member function for non-object in ...
Why is this happening? Does this mean that I need to open two different connections? Is there a way to avoid this (I like to store the details of the SQL connection in a single file)?
Here is the code:
$db = new mysqli("localhost", "root", "", "database");
$stmt = $db->prepare("UPDATE posts SET vote_".$_POST['vote']." = vote_".$_POST['vote']." + 1 WHERE id=?");
$stmt->bind_param('s', $_POST['id_post']);
$stmt->execute();
$stmt->close();
$stmt = $db->prepare("INSERT INTO votes (kind, users_id, posts_id) VALUES (?, ?, ?)");
$stmt->bind_param('sss',$_POST['vote'],$_POST['id_user'],$_POST['id_post']);
$stmt->execute();
$stmt->close();
source
share