Jump to content

Recommended Posts

When I try to run the following code, I either get MySQL errors, or nothing shows...

 

<?php
if($act == 'view') {
if (!$topic_id){
	echo "<b><i><a href='$PHP_SELF?act=view&forum=$id&topic=create'>Create Topic</a></i></b><br><br>";
	echo "<table border=1><tr>
		<td><b><center>Topic Name:</center></b></td>
		<td><b><center>Posted By:</center></b></td>
		<td><b><center>Quick Desc:</center></b></td>
		<td><b><center>Posted On:</center></b></td>
		<td><b><center>Last Poster:</center></b></td>
		</tr>";
	$topic_sql = mysql_query("SELECT * FROM forum_topics WHERE f_id=$id");
	while($row2=mysql_fetch_array($topic_sql)) {
		echo "<tr><td><font size=2><b><a href='$PHP_SELF?act=view&forums=$id&topic=$row2[iD]'>$row2[t_name]</font></b></font></td>
			<td><font size=2><u>$row2[posted_by]</u></font></td>
			<td><font size=1><i>$row2[t_desc]</i></font></td>
			<td><font size=2>$row2[time_posted]</font></td>
			<td><font size=2>last poster</font></td>
			</tr>";
	}
	echo"</table>";
}
if (isset($topic_id)){
	if ($topic_id == 'create'){
		$topic_name = $_POST['topic_name'];
		$message = $_POST['message'];
		if (!isset($topic_name)){
			echo "<form action='$PHP_SELF?act=view&forum=$id&topic=create' method='post'>
				Topic Name:<br /><input type='text' name='topic_name' /><br />
				Message:<br /><textarea rows='4' cols='40' name='message'></textarea><br />
				<input type='submit' value='Create Topic' />
				</form>";
		}
		if (isset($topic_name)){
			if (empty($topic_name) || empty($message)){
				showerror("You left one of the fields blank.");
			}
			else {     //this mysql query wont run V
				mysql_query("INSERT INTO forum_topics (f_id, t_name, t_desc, t_msg, time_posted, posted_by, last_poster) VALUES('$id', '$topic_name', 'eee', '$message', 'time()',  '$Yourname', 'IDK'") or die(mysql_error());
				echo "You have created the topic <b>$topic_name</b>";
			}
		}
	}
	else {
		global $id, $row2;
		$p_message = $_POST['p_message'];
		$sql = "SELECT * FROM forum_posts WHERE top_id=$topic_id";
		$result10 = mysql_query($sql);
		if (!isset($p_message)){
		global $id, $row2;
			echo "<table border='1'>//This code won't show results V
				<tr><td><a href='profiles.php?user=$row2[posted_by] f'>$row2[posted_by] f</a></td><td>$row2[t_name] c</td></tr>
				<tr><td>Avatar</td><td>$row2[t_msg] asdfgsdfgfdgsfgfgfs</td></tr></table><br /><br />";
			if (mysql_num_rows($result10) == 0){
				echo "This topic has no reply's yet.";
			}
			while ($row4 = mysql_fetch_array($result10)){
				echo "<table border='1' width=70%>
				<tr><td width='20%'><a href='profiles.php?user=$row4[post_name]'>$row4[post_name]</a></td><td>RE: HAVE TO FIX THIS...$row4[t_name]</td></tr>
				<tr><td>Avatar</td><td>$row4[post_msg]</td></tr></table><br /><br />";
			}
			echo "<form action='$PHP_SELF?act=view&forum=$id&topic=$topic_id' method='post'>
				<br /><br />Message: <textarea cols='40' rows='4' name='p_message'></textarea><br />
				<input type='submit' value='Post Message' />
				</form>";
		}
		if (isset($p_message)){
			if (strlen($p_message) > 5000){
				showerror("<br />Your post was more then 5000 characters.");
			}
			if (empty($p_message)){
				showerror("<br />You left the message field blank.");
			}
			else {
				mysql_query("INSERT INTO forum_posts (post_name, post_msg, time_posted, top_id) VALUES('$Yourname', '$p_message', 'time()', '$topic_id')");
				echo "You have just posted a reply. Go back and refresh to see it.";
			}
		}
	}
}
}
?>

 

Help is appreciated.

 

--

DJ

Link to comment
https://forums.phpfreaks.com/topic/63875-solved-problems-with-my-code/
Share on other sites

When I try to run the following code, I either get MySQL errors, or nothing shows...

 

<?php
if($act == 'view') {
if (!$topic_id){
	echo "<b><i><a href='$PHP_SELF?act=view&forum=$id&topic=create'>Create Topic</a></i></b><br><br>";
	echo "<table border=1><tr>
		<td><b><center>Topic Name:</center></b></td>
		<td><b><center>Posted By:</center></b></td>
		<td><b><center>Quick Desc:</center></b></td>
		<td><b><center>Posted On:</center></b></td>
		<td><b><center>Last Poster:</center></b></td>
		</tr>";
	$topic_sql = mysql_query("SELECT * FROM forum_topics WHERE f_id=$id");
	while($row2=mysql_fetch_array($topic_sql)) {
		echo "<tr><td><font size=2><b><a href='$PHP_SELF?act=view&forums=$id&topic=$row2[iD]'>$row2[t_name]</font></b></font></td>
			<td><font size=2><u>$row2[posted_by]</u></font></td>
			<td><font size=1><i>$row2[t_desc]</i></font></td>
			<td><font size=2>$row2[time_posted]</font></td>
			<td><font size=2>last poster</font></td>
			</tr>";
	}
	echo"</table>";
}
if (isset($topic_id)){
	if ($topic_id == 'create'){
		$topic_name = $_POST['topic_name'];
		$message = $_POST['message'];
		if (!isset($topic_name)){
			echo "<form action='$PHP_SELF?act=view&forum=$id&topic=create' method='post'>
				Topic Name:<br /><input type='text' name='topic_name' /><br />
				Message:<br /><textarea rows='4' cols='40' name='message'></textarea><br />
				<input type='submit' value='Create Topic' />
				</form>";
		}
		if (isset($topic_name)){
			if (empty($topic_name) || empty($message)){
				showerror("You left one of the fields blank.");
			}
			else {     //this mysql query wont run V
				mysql_query("INSERT INTO forum_topics (f_id, t_name, t_desc, t_msg, time_posted, posted_by, last_poster) VALUES('$id', '$topic_name', 'eee', '$message', 'time()',  '$Yourname', 'IDK')") or die(mysql_error()); // <- problem here
				echo "You have created the topic <b>$topic_name</b>";
			}
		}
	}
	else {
		global $id, $row2;
		$p_message = $_POST['p_message'];
		$sql = "SELECT * FROM forum_posts WHERE top_id=$topic_id";
		$result10 = mysql_query($sql);
		if (!isset($p_message)){
		global $id, $row2;
			echo "<table border='1'>//This code won't show results V
				<tr><td><a href='profiles.php?user=$row2[posted_by] f'>$row2[posted_by] f</a></td><td>$row2[t_name] c</td></tr>
				<tr><td>Avatar</td><td>$row2[t_msg] asdfgsdfgfdgsfgfgfs</td></tr></table><br /><br />";
			if (mysql_num_rows($result10) == 0){
				echo "This topic has no reply's yet.";
			}
			while ($row4 = mysql_fetch_array($result10)){
				echo "<table border='1' width=70%>
				<tr><td width='20%'><a href='profiles.php?user=$row4[post_name]'>$row4[post_name]</a></td><td>RE: HAVE TO FIX THIS...$row4[t_name]</td></tr>
				<tr><td>Avatar</td><td>$row4[post_msg]</td></tr></table><br /><br />";
			}
			echo "<form action='$PHP_SELF?act=view&forum=$id&topic=$topic_id' method='post'>
				<br /><br />Message: <textarea cols='40' rows='4' name='p_message'></textarea><br />
				<input type='submit' value='Post Message' />
				</form>";
		}
		if (isset($p_message)){
			if (strlen($p_message) > 5000){
				showerror("<br />Your post was more then 5000 characters.");
			}
			if (empty($p_message)){
				showerror("<br />You left the message field blank.");
			}
			else {
				mysql_query("INSERT INTO forum_posts (post_name, post_msg, time_posted, top_id) VALUES('$Yourname', '$p_message', 'time()', '$topic_id')");
				echo "You have just posted a reply. Go back and refresh to see it.";
			}
		}
	}
}
}
?>

 

Help is appreciated.

 

--

DJ

 

mysql_query("INSERT INTO forum_topics (f_id, t_name, t_desc, t_msg, time_posted, posted_by, last_poster) VALUES('$id', '$topic_name', 'eee', '$message', 'time()',  '$Yourname', 'IDK'") <-- there is your problem

 

mysql_query("INSERT INTO forum_topics (f_id, t_name, t_desc, t_msg, time_posted, posted_by, last_poster) VALUES('$id', '$topic_name', 'eee', '$message', 'time()',  '$Yourname', 'IDK')")  

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.