Code:
// get value of id that sent from address bar
$id=filter_input(INPUT_GET, 'id', FILTER_VALIDATE_INT);
if ($id === false) {
//filter failed
die('id not a number');
}
if ($id === null) {
//variable was not set
die('id not set');
}
//white list table
$safe_tbl_name = '';
switch($tbl_name){
case 'Table1':
$safe_tbl_name = 'MyTable1';
break;
case 'Table2':
$safe_tbl_name = 'MyTable2';
break;
default:
$safe_tbl_name = 'forum_questions';
};
$sql="SELECT * FROM `$safe_tbl_name` WHERE id=?";
if ($stmt = $con->prepare($sql)){
$stmt->bind_param("s", $id);
$stmt->execute();
}
else{
//error !! don't go further
var_dump($con);
}
$stmt->bind_result($result);
$rows = $stmt->fetch_all(MYSQLI_ASSOC);
?>
<table width="400" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<td><table width="100%" border="0" cellpadding="3" cellspacing="1" bordercolor="1" bgcolor="#FFFFFF">
<tr>
<td bgcolor="#F8F7F1"><strong><?php echo $rows['topic']; ?></strong></td>
</tr>
<tr>
<td bgcolor="#F8F7F1"><?php echo $rows['detail']; ?></td>
</tr>
<tr>
<td bgcolor="#F8F7F1"><strong>By :</strong> <?php echo $rows['name']; ?> <strong>Email : </strong><?php echo $rows['email'];?></td>
</tr>
<tr>
<td bgcolor="#F8F7F1"><strong>Date/time : </strong><?php echo $rows['datetime']; ?></td>
</tr>
</table></td>
</tr>
</table>
And I get this error:
Warning: mysqli_stmt::bind_result(): Number of bind variables doesn't match number of fields in prepared statement in C:\wamp64\www\forrrumm\view_topic.php on line 47
And this:
Fatal error: Call to undefined method mysqli_stmt::fetch_all() in C:\wamp64\www\forrrumm\view_topic.php on line 49