I use prepared statements rather frequently to insert data, but I'm trying to select data and having an issue I can't seem to wrap my head around.
This code does not work at all. No error, just no results:
$student_name = "Student, Sample";
$student_number = "";
$SQLStmt = $db->prepare( "SELECT student_number FROM table WHERE `name` = ?" );
$SQLStmt->bind_param( "s", $student_name );
$SQLStmt->bind_result( $student_number );
$SQLStmt->execute();
$SQLStmt->store_result();
echo $student_number;
This code works just fine:
$student_name = "Student, Sample";
$student_number = "";
$SQLStatement = "SELECT student_number FROM table WHERE `name` = '".$student_name."'";
$result = $db->query($SQLStatement);
$myrow = $result->fetch_assoc();
echo $myrow['student_number'];
Any ideas would be most appreciated. Thanks!