I'm trying to get the name and email from users table where the userid is the session['id'] which I set somewhere else. BTW, is this a good practice, putting user id in session variables?
EDIT: Upon further testing, this problem only occurs when I retrieve things from the users table, single or multiple columns. Using WHERE email/username/name/etc =
other than WHERE userid =
gives the same bind_param() error. But this only happens when using prepared statement. And there's no typo.
The prepared statement gives me Fatal error: Call to a member function bind_param() on a non-object
. The same code (in the same php file, just below the following code) when retrieving one column works just fine.
$sessionid = $_SESSION['id'];
// Prepare
$stmt = $conn->prepare('SELECT name, email FROM users WHERE userid = ?');
// Set Parameters
$ps_userid = $sessionid;
// Bind
$stmt->bind_param("i", $ps_userid);
// Execute
$stmt->execute();
$stmt->bind_result($mail_name, $mail_email);
$stmt->fetch();
`The code below works just fine
$data = mysqli_query($conn, 'SELECT name, email FROM users WHERE userid='.$_SESSION["id"]);
$row = mysqli_fetch_array($data, MYSQL_ASSOC);
$mail_name = $row['name'];
$mail_email = $row['email'];