问题
I'm trying to add a link onto my page with the code below but for some reason it isn't showing up, I've put the area in bold and it all looks correct to me. I presented the whole piece of code as I wasn't sure if it was something to do with the code outside of the bit I have put in bold.
<?php session_start();?>
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>Forum</title>
<link href="styles.css" rel="stylesheet" type="text/css">
<script>var __adobewebfontsappname__="dreamweaver"</script>
<script src="http://use.edgefonts.net/source-sans-pro:n6:default.js" type="text/javascript"></script>
</head>
<body>
<div id="wrapper">
<header id="top">
<h1>ITSize</h1>
<nav id="mainnav">
<ul>
<li><a href="Index.php">Home</a></li>
<li><a href="Fourth Page.html">Register</a></li>
<li><a href="Second Page.html">Revise</a></li>
<li><a href="Forum.php">Forum</a></li>
</ul>
</nav>
</header>
<article id="main">
<br>
<br>
<?php
include_once("DBconnect.php");
$cid= $_GET['cid'];
**if (isset($_SESSION['uid'])){
$logged= " | <a href='create_topic.php?cid=".$cid."'>Click here to create a topic</a>";
}else{
$logged = " | Please log in to create topics in this forum";**
}
$sql = "SELECT id FROM categories WHERE id='".$cid."' LIMIT 1";
$res = mysql_query($sql) or die(mysql_error());
if (mysql_num_rows($res) ==1){
$sql2 = "SELECT * FROM topics WHERE category_id='".$cid."' ORDER BY topic_reply_date DESC";
$res2 = mysql_query($sql2) or die(mysql_error());
if (mysql_num_rows($res2)>0){
$topics .= "<table width='100%' style='border-collapse: collapse;'>";
$topics .= "<tr><td colspan='3'<a href='Forum.php'>Return To Forum</a>".$logged."</td></tr>";
$topics .= "<tr style='background-colour: #dddddd;'><td>Topic Title</td><td width='65' align='center'>Replies</td><td width='65' align='center'>Views</td</tr>";
while ($row = mysql_fetch_assoc($res2)){
$tid = $row['id'];
$title = $row['topic_title'];
$views = $row['topic_views'];
$date = $row['topic_date'];
$creator =$row['topic_creator'];
$topics .= "<tr><td><a href='view_topic.php?cid=".$cid."&tid=".$tid.">".$title."</a><spa class='post_info'>Posted by:".$creator." on ".$date."</span></td><td align='center'>0</td><td align='center'>".$views."</td></tr>";
$topics .="<tr><td colspan='3'></td></tr>";
}
$topics .="</table>";
}else{
echo"<p> There are no topics in this category yet</p><br>";
echo "<a href='Forum.php'>Return To Forum Page</a><br><br>";
}
}
else{
echo"<p> You are trying to view a category that does not exist</p><br>";
echo "<a href='Forum.php'>Return To Forum Page</a><br><br>";
}
?>
</article>
<aside id="sidebar">
</aside>
<footer><a href="Third Page.html">My Account</a>
</footer>
</div>
</body>
</html>
回答1:
after reading whole code :P found some markup errors :) .
in this snippet these all errors are removed .. now it should work fine .
<?php session_start(); ?>
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>Forum</title>
<link href="styles.css" rel="stylesheet" type="text/css" />
<script>var __adobewebfontsappname__="dreamweaver"; </script>
<script src="http://use.edgefonts.net/source-sans-pro:n6:default.js" type="text/javascript"></script>
</head>
<body>
<div id="wrapper">
<header id="top">
<h1>ITSize</h1>
<nav id="mainnav">
<ul>
<li><a href="Index.php">Home</a></li>
<li><a href="Fourth Page.html">Register</a></li>
<li><a href="Second Page.html">Revise</a></li>
<li><a href="Forum.php">Forum</a></li>
</ul>
</nav>
</header>
<article id="main">
<br />
<br />
<?php
require_once("DBconnect.php");
$cid = $_GET['cid'];
if (isset($_SESSION['uid'])){
$logged = " | <a href='create_topic.php?cid=".$cid."'>Click here to create a topic</a>";
}else{
$logged = " | Please log in to create topics in this forum";
}
$sql = "SELECT id FROM categories WHERE id='".$cid."' LIMIT 1";
$res = mysql_query($sql) or die(mysql_error());
if (mysql_num_rows($res) == 1){
$sql2 = "SELECT * FROM topics WHERE category_id='".$cid."' ORDER BY topic_reply_date DESC";
$res2 = mysql_query($sql2) or die(mysql_error());
if (mysql_num_rows($res2)>0){
$topics = "<table width='100%' style='border-collapse: collapse;'>";
$topics .= "<tr>
<td colspan='3'>
<a href='Forum.php'> Return To Forum </a>".$logged."</td>
</tr>";
$topics .= "<tr style='background-colour: #dddddd;'>
<td>Topic Title</td>
<td width='65' align='center'>Replies</td>
<td width='65' align='center'>Views</td>
</tr>";
while ($row = mysql_fetch_array($res2)){
$tid = $row['id'];
$title = $row['topic_title'];
$views = $row['topic_views'];
$date = $row['topic_date'];
$creator = $row['topic_creator'];
$topics .= "<tr>
<td> <a href='view_topic.php?cid=".$cid."&tid=".$tid.">".$title."</a>
<span class='post_info'>Posted by:".$creator." on ".$date."</span>
</td>
<td align='center'>0</td>
<td align='center'>".$views."</td>
</tr>";
$topics .="<tr>
<td colspan='3'> </td>
</tr>";
}
$topics .="</table>";
echo $topics;
}else{
echo"<p> There are no topics in this category yet</p><br>";
echo "<a href='Forum.php'>Return To Forum Page</a><br><br>";
}
}
else{
echo"<p> You are trying to view a category that does not exist</p><br>";
echo "<a href='Forum.php'>Return To Forum Page</a><br><br>";
}
?>
</article>
<aside id="sidebar">
</aside>
<footer><a href="Third Page.html">My Account</a>
</footer>
</div>
</body>
</html>
EDIT Code : Updated .
回答2:
You have set the variable $logged to equal your text and then put $logged within the $topics variable and I can't see where you output topics try adding echo $topics to your code
<?php
include_once("DBconnect.php");
$cid= $_GET['cid'];
if (isset($_SESSION['uid'])){
$logged= " | <a href='create_topic.php?cid=".$cid."'>Click here to create a topic</a>";
}else{
$logged = " | Please log in to create topics in this forum";
}
$sql = "SELECT id FROM categories WHERE id='".$cid."' LIMIT 1";
$res = mysql_query($sql) or die(mysql_error());
if (mysql_num_rows($res) ==1){
$sql2 = "SELECT * FROM topics WHERE category_id='".$cid."' ORDER BY topic_reply_date DESC";
$res2 = mysql_query($sql2) or die(mysql_error());
if (mysql_num_rows($res2)>0){
$topics .= "<table width='100%' style='border-collapse: collapse;'>";
$topics .= "<tr><td colspan='3'<a href='Forum.php'>Return To Forum</a>".$logged."</td></tr>";
$topics .= "<tr style='background-colour: #dddddd;'><td>Topic Title</td><td width='65' align='center'>Replies</td><td width='65' align='center'>Views</td</tr>";
while ($row = mysql_fetch_assoc($res2)){
$tid = $row['id'];
$title = $row['topic_title'];
$views = $row['topic_views'];
$date = $row['topic_date'];
$creator =$row['topic_creator'];
$topics .= "<tr><td><a href='view_topic.php?cid=".$cid."&tid=".$tid.">".$title."</a><spa class='post_info'>Posted by:".$creator." on ".$date."</span></td><td align='center'>0</td><td align='center'>".$views."</td></tr>";
$topics .="<tr><td colspan='3'></td></tr>";
}
$topics .="</table>";
// OUTPUT $topics HERE
echo $topics;
}else{
echo"<p> There are no topics in this category yet</p><br>";
echo "<a href='Forum.php'>Return To Forum Page</a><br><br>";
}
}
else{
echo"<p> You are trying to view a category that does not exist</p><br>";
echo "<a href='Forum.php'>Return To Forum Page</a><br><br>";
}
?>
Also, just FYI bolding doesn't seem to work on code.
来源:https://stackoverflow.com/questions/22882209/link-isnt-appearing-on-my-page