Jump to content

Recommended Posts

I  have been on here a few times  already and I have found some excellent solutions to my questions! Well, here I am again with hopefully the last question, at least for this forum I am building, no promises though :D

 

Here is the code. It is used to reply to a topic of the forum.

 

<?php
//connect to server
$host = 'XXXXXX.net'; 
$user = 'XXXXXXXXXXX';
$pass = '#########';
$database = 'TylorsTestDB';
mysql_connect($host,$user,$pass,$database) or die(mysql_error());
mysql_select_db($database) or die(mysql_error());

//Check to see if we are showing the form or adding
if (!$_POST){
//Showing the forum; check for required item in query string
if (!isset($_GET["post_id"])) {
	header("Location: topiclist.php");
	exit;
}

//still have to verify topic and post
$verify_sql = "SELECT ft.topic_id, ft.topic_title FROM forum_posts AS fp LEFT JOIN forum_topics AS ft ON fp.topic_id =	
ft.topic_id WHERE fp.post_id = '".$_GET["post_id"]."'";

$verify_res = mysql_query($verify_sql) or die(mysql_error());

if (mysql_num_rows($verify_res) < 1){
//This post or topic dosn't exist
header("Location:topiclist.php");
exit;
} else {
	//Get the topic id and title
	while($topic_info = mysql_fetch_array($verify_res)); {
		$topic_id = $topic_info['topic.php'];
		$topic_title = stripslashes($topic_info['topic_title']);
		} 
echo "
<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">
<html xmlns=\"http://www.w3.org/1999/xhtml\">
<head>
<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />
<title>Post Your Reply in ".$topic_title."</title>
</head>

<body>
<h1>Post Your Reply in ".$topic_title."</h1>
<form method=\"post\" action=\"".$_SERVER["PHP_SELF"]."\">

<p><strong>Your Email Address:</strong><br />
<input type=\"text\" name=\"post_owner\" size=\"40\" maxlength=\"150\">
</p>

<p><strong>Post Text</strong><br />
<textarea name=\"post_text\" rows=\"8\" cols=\"40\" wrap=\"virtual\"></textarea>
<input type=\"hidden\" name=\"topic_id\" value=\"$topic_id\">
</p>

<p><input type=\"submit\" name=\"submit\" value\"Add Post\"></p>
</form>


</body>
</html>";
}
//Free Result
mysql_free_result($verify_res);

}else if ($_POST) {
//check for required items from form
if ((!$_POST["topic_id"]) || (!$_POST["post_text"]) ||
(!$_POST["post_owner"])){
header("Location:topiclist.php");
exit;
}

//Add the post

$add_post_sql = "INSERT INTO forum_posts (topic_id, post_text, post_create_time, post_owner)
VALUES (' ".$_POST["topic_owner"]." ')";
$add_post_res = mysql_query($add_post_sql) or die (mysql_error());

//Redirect user to topic
header("Location: showtopic.php?topic_id=".$_POST["topic_id"]);
exit;
}

?>

 

When I go to it, it pops up and I get a  section to enter in my email and reply (just like it is supposed to work). One weird thing is that the submit button says “Submit Query” when I told it to say “Add Post”. But when I click it I get taken back to the previous page (topiclist.php). My main questions are,

 

1. Why won’t it enter the information into the database

2. Why the submit button says “Submit Query”

 

I am guessing the trouble is in the “else if” statement towards the bottom of the page (because that is the only place where it redirects to topiclist.php). So if that is failing then I am guessing that for some reason it isn’t  finding $topic_id and $post_text. (I am talking about lines 65-71 if it helps). I could be completely wrong but that was all I could come up with.

 

I am using mysqladmin through Godaddy. Any help would of course be greatly appreciated. Thanks so much!

 

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.