All pastes #607651 Raw Edit

Stuff

public text v1 · immutable
·published 2007-07-07 20:04 UTC
rendered paste body
<?php
//includes the connection script
require_once "../includes/connection.php";
require_once "../includes/header.html";
?>
<div id="col-l-2">
<div class="box">
<?php
//if the form is submitted then the post is set so run the script to update the database
if ($_POST)
	{
	// this is a loop foreach $_POST that runs the commands inside the loop (loop = {})
	foreach ($_POST as $name => $value)
		{
				//check that all the fields have been filled
		if (empty($value))
			{
			$error = '<h1>Error - Please fill in all fields</h1>'."\n\r";
			echo "please fill in all fields before submitting";
			//require_once "../includes/footer.php";
			exit;
			}
		// strip the html tags off each post and stop the mysql injection (mysql injection = bad!)
		$_POST[$name] = strip_tags(mysql_real_escape_string($value));
		}
	// this is the sql query to update the database
	$query = "INSERT INTO `comments` (name, comment)
	VALUES ('{$_POST[name]}', '{$_POST[comment]}')";
	mysql_query($query) or die(mysql_error());
	echo "thankyou for your comment";
	}
else
	{
	?>
<h3>Please Leave A Comment</h3>
	<form name="comments" method="post" action="">

					<label for="name">Name</label><br/>
					<input type="text" name="name" size="35" id="name"/>
					<br/>
					<br/>
					<label for="comment">Comment</label><br/>
					<textarea name="comment" cols="27" rows="6" id="comment"></textarea>
					<br/>
					<br/>
					<input type="submit" value="submit entry" name="submit"/>
	</form>
	<?php
	}  
?>
</div>
</div>

<div id="col-r-2">
<?php
$query = "SELECT * FROM `comments` ORDER BY 'cmntID' DESC LIMIT 50";
$result = mysql_query($query) or die("Error comments cannot be displayed");
if (mysql_num_rows($result) < 1)
	{
	echo "<h2>Error no comments!</h2>\n\r";
	}
while ($row = mysql_fetch_assoc($result))
	{
	$row['title'] = stripslashes($row['name']);
	$row['text'] = stripslashes($row['comment']);
	$row['text'] = nl2br($row['comment']);
	
	echo '<h3><b>'.$row['name']."</b></h3>";
	echo '<p>'.$row['comment']."\r\n</p>";
	}
?>
</div>

<div class="clear"></div>
<?php
require_once "../includes/footer.html";
?>