我的新错误是这样的: 您的SQL语法有错误;检查与您的MySQL服务器版本对应的手册,以便在第1行附近使用正确的语法')并键入='o'' 有人可以帮助修复此代码和此代码中的任何其他错误:
<?php
session_start();
require"db_connect.php";
//get the page id
if(isset($_GET['id']) && is_numeric($_GET['id'] ))
{
$id = $_GET['id'] ;
} else { die("Error!"); }
//Check to see if the id is a valid id
$idCheck = $db->query("SELECT * FROM forum_tabl WHERE forum_id = '$id'");
if($idCheck->num_rows !==1){
die("error");
}
$row = $idCheck->fetch_object();
$sql = "SELECT post_id, post_title FROM forum_post WHERE forum_id=) AND type='o'";
if($query = $db->prepare($sql)){
$query->bind_param('s', $id);
$query->bind_result($post_id, $post_title);
$query->execute();
$query->store_result();
}else{
echo $db->error;
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="style.css" />
<title><?php= $row->forum_name?>!</title>
<html>
<head>
<body>
<div id="page">
<center><h1>Welcome to Our forms.</h1></center>
<h2>Our minecraft forum is displayed below</h2>
<table width="100%">
<?php if($query->num_rows!=0):?>
<?php while($query-fetch()):?>
<tr>
<td><?- $post_title?></td
</tr>
<?php endwhile;?>
<?php else:?>
<tr>
<td><p>No Posts yet!</p></td>
</tr>
<?php endif;?>
</html>
</head>
</body>
答案 0 :(得分:1)
你应该用冒号替换分号:
<?php while($query->fetch()): ?>
<tr>
<td><?- $post_title?></td
</tr>
<?php endwhile;?>
if
和endif
条件相同。