<?php
$self = $_SERVER['PHP_SELF'];
$ipaddress = ("$_SERVER[REMOTE_ADDR]");
include ('db.php');
$connect = mysql_connect($host,$username,$password) or die('query failed'. mysql_error($db));
mysql_select_db = ($db,$connect) or die('query failed'. mysql_error($db));
if(isset($_POST['send'])) {
if(empty($_POST['name'])) || if(empty($_POST['email'])) || if(empty($_POST['post'])){
echo('Make sure you fill all the required fields');
} else {
$name = $_POST['name'];
$email = $_POST['email'];
$post = $_POST['post'];
$sql = "INSERT INTO shouts SET name='$name', email='$email', post='$post', ipaddress='$ipaddress';";
if(@mysql_query($sql)) {
echo 'Thanks for shouting';
} else {
echo 'There was an expected error';
}
}
}
$query = "SELECT * FROM shouts ORDER BY `id` DESC LIMIT 8;";
$result = @mysql_query("$query") or die('<p class="error">There was an unexpected error grabbing shouts from the database.</p>');
// while we still have rows from the db, display them
while ($row = mysql_fetch_array($result)) {
$ename = stripslashes($row['name']);
$eemail = stripslashes($row['email']);
$epost = stripslashes($row['post']);
echo('<li><div class="meta"><img src="'.$grav_url.'" alt="Gravatar" /><p>'.$ename.'</p></div><div class="shout"><p>'.$epost.'</p></div></li>');
}
?>
<!-- at the bottom of the page, we display our comment form -->
<form action="<?php $self ?>" method="post">
<h2>Shout!</h2>
<div class="fname"><label for="name"><p>Name:</p></label><input name="name" type="text" cols="20" /></div>
<div class="femail"><label for="email"><p>Email:</p></label><input name="email" type="text" cols="20" /></div>
<textarea name="post" rows="5" cols="40"></textarea>
<input name="send" type="hidden" />
<p><input type="submit" value="send" /></p>
</form>