computernoob Posted July 30, 2009 Share Posted July 30, 2009 So after running a statement, binding the parameters and then executing the statement, I have no clue how to catch the result. I know bind_result() will convert it to prepared variables or w/e they call it, but I want to get a hold of the actual value. This is my current code: $conn = connect(); $sql = "SELECT id, name FROM users WHERE email=? AND password=? AND role='admin'"; $stmt = $conn->prepare($sql) or die(mysqli_error($conn)); if($stmt){ $stmt->bind_param("ss", $email, $password); $stmt->execute(); $stmt->bind_result($id, $name); if($stmt->fetch()){ // how do I catch $id and $name so I can do something like $_SESSION['id'] = $id } } So essentially, $id and $name can only be used in a bound expression like printf("%s", $name) ... but how can I get $name to be the actual value so I can do something like $_SESSION['name'] = $name Thanks for all the help in advance! Link to comment https://forums.phpfreaks.com/topic/168077-getting-mysqli-result-from-bound-statement/ Share on other sites More sharing options...
xtopolis Posted July 30, 2009 Share Posted July 30, 2009 /* fetch values */ while ($stmt->fetch()) { //this is like " while($row = mysql_fetch_array($result)) { echo $id . " - " . $name . "<br>"; } /* close statement */ $stmt->close(); Copied from the manual, example 1 Link to comment https://forums.phpfreaks.com/topic/168077-getting-mysqli-result-from-bound-statement/#findComment-886513 Share on other sites More sharing options...
computernoob Posted July 30, 2009 Author Share Posted July 30, 2009 Thanks. I found out my problem. I actually didn't called session_start() on the update page. Appreciate your input though! Link to comment https://forums.phpfreaks.com/topic/168077-getting-mysqli-result-from-bound-statement/#findComment-886527 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.