Hey guys!
I have part of the following code but I can’t seem to get $row[‘name’]to display. Is it possible to query a previous query with prepare statement or must I query it again? I have also tried to move the echo statement around various {}but doesn’t seem to work:
<?php
$id = $_GET['id'];
if ($id) {
$sql = "SELECT * FROM forum_sub_cats WHERE id = ?;";
if(!mysqli_stmt_prepare($stmt, $sql)) {
echo "SQL error";
} else {
mysqli_stmt_bind_param($stmt, "i", $id);
mysqli_stmt_execute($stmt);
$result = mysqli_stmt_get_result($stmt);
$resultCheck = mysqli_num_rows($result);
$admin_user_level = $admin_user_level + '1';
if ($resultCheck < 1) {
echo "The forum you are trying to create a topic on, does not exist\n";
} else {
$row1 = mysqli_fetch_assoc($result);
if ($row1['admin'] == 0) {
echo "You are not an administrator, therefore you cannot post on this forum!\n";
} else {
if (!$_POST['submit']) {
echo "<table border=\"0\" cellspacing=\"3\" cellpadding=\"3\">\n";
echo "<form method=\"POST\" action=\"./forum_main.php?act=create&id\">\n";
echo "<tr><td>Form Sub Category</td><td><select name=\"cat\">\n";
$sql2 = "SELECT * FROM forum_cats WHERE admin < ?;";
if(!mysqli_stmt_prepare($stmt, $sql2)) {
echo "SQL error";
} else {
mysqli_stmt_bind_param($stmt, "i", $admin_user_level);
mysqli_stmt_execute($stmt);
$result2 = mysqli_stmt_get_result($stmt);
while ($row = mysqli_fetch_assoc($result2)) {
$row = $row['id'];
$sql3 = "SELECT * FROM forum_sub_cats WHERE cid = ?;";
if(!mysqli_stmt_prepare($stmt, $sql3)) {
echo "SQL error";
} else {
mysqli_stmt_bind_param($stmt, "i", $row);
mysqli_stmt_execute($stmt);
$result3 = mysqli_stmt_get_result($stmt);
echo "<option value=\"0\">".$row['name']."</option>\n";
while ($row2 = mysqli_fetch_assoc($result3)) {
$selected = ($row2['id'] == $id) ? "SELECTED": "";
echo "<option value=\"".$row2['id']."\"".$selected."> ".$row2['name']."</option>\n";
}