Jump to content

>:( It's not sending the info to the database!


Tylor_Famous

Recommended Posts

I have tried many times to get this to send the info to the database and it just isn't working... It is for a forum I am working on and this is the "reply to a topic" code and everything seems like it should work but it just WONT send the dang info to the database! Any help would be GREAT!

 

<?php
//connect to server
$host = 'myserver'; 
$user = 'XXXXXXX';
$pass = '######';
$database = 'TylorsTestDB';

mysql_connect($host,$user,$pass) 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"]."'";

//Connecting here again might be redundent but I am trying to get it to work so...
mysql_connect($host,$user,$pass) or die(mysql_error());
mysql_select_db($database) or die(mysql_error());
$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_id'];
		$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_id"]." ' , ' ".$_POST["post_text"]." ', '' , ' ".$_POST["post_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;
}

?>

Link to comment
https://forums.phpfreaks.com/topic/87700-its-not-sending-the-info-to-the-database/
Share on other sites

Remove this as stated above

 

//Connecting here again might be redundent but I am trying to get it to work so...

mysql_connect($host,$user,$pass) or die(mysql_error());

mysql_select_db($database) or die(mysql_error());

 

Also, is post_create_time a required field in your DB?  If so, do you have a default set since you are not inserting it?

 

If the query is failing, you should get a error, are there no errors?  Have you checked your Log File to see if the errors are suppressed to the browser?

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.