Jump to content


Photo

Wrong message being displayed in my script


  • Please log in to reply
2 replies to this topic

#1 Perad

Perad
  • Members
  • PipPipPip
  • Advanced Member
  • 287 posts

Posted 12 October 2006 - 02:57 PM

My script works in that it posts news onto my website. The problem is that when the news has been posted the script says that an error has taken place instead of posting that it was completed successfully.

Could someone help me work out why?

<?php # Script 6.6 - addnews.php

// Set the page title and include the HTML header.
$page_title = 'Add News';

if (isset($_POST['submit'])) { // Handle the form.

	$message = NULL; // Create an empty new variable.
	
	// Check for a first name.
	if (empty($_POST['title'])) {
		$t = FALSE;
		$message .= '<p>You forgot to enter the title!</p>';
	} else {
		$t = $_POST['title'];
	}
	
	// Check for a last name.
	if (empty($_POST['content'])) {
		$c = FALSE;
		$message .= '<p>You forgot to enter the content!</p>';
	} else {
		$c = $_POST['content'];
	}
	
	if ($t && $c) { // If everything's OK.
		require_once ('../alink.php');// Connect to the db.
		
		// Make the query.
		$query = "INSERT INTO news(id, postdate, title, newstext) VALUES( '', NOW(), '$t', '$c')";
   		mysql_query($query);
		if ($result) { // If it ran OK.
		
		// Confirmation.
		echo '<p><b>The news article has been added successfully!</b></p>';
		exit(); // Quit the script.
			
		} else { // If it did not run OK.
			$message = '<p>The news couldn\'t be added. If the problem persists please e-mail the administrator.</p><p>' . mysql_error() . '</p>'; 
		}
		
		mysql_close(); // Close the database connection.

	} else {
		$message .= '<p>Please try again.</p>';		
	}

} // End of the main Submit conditional.

// Print the message if there is one.
if (isset($message)) {
	echo '<font color="red">', $message, '</font>';
}
?>

<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<fieldset><legend>Warning! You are posting news which will appear on the front page of the website!</legend>

	<p>Please check and double check everything you type before posting. Thanks</p>
    <p>Title:<input type="text" width="30" name="title" value="title"></p>
    <TEXTAREA cols="40" rows="5" name="content" value="content"></TEXTAREA><br />
    <input type="submit" name="submit" value="submit" />
	
</fieldset></FORM>


#2 komquat

komquat
  • Members
  • PipPipPip
  • Advanced Member
  • 130 posts
  • LocationHoughton, MI

Posted 12 October 2006 - 03:00 PM

I think you forgot $result = mysql_query(query);

#3 Perad

Perad
  • Members
  • PipPipPip
  • Advanced Member
  • 287 posts

Posted 12 October 2006 - 03:15 PM

EDIT: Solved, the line above missed the $ on query.

Thanks for the help mate ;)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users