aspdude2004
05-02-2004, 10:16 PM
please can you tell me what is wrong with this : : : : it doesnt display : -
<?php
session_start(); //start session
// You just need to configure these 4 variables to match your server.
$db_host = "localhost"; // mySQL database host
$db_user = "***"; // mySQL database user
$db_password = "*******"; // mySQL database password
$db_name = "****"; // the name of your mySQL database
if($_POST['submit']) {
// 1. Validate it, by checking all the form inputs were filled in
$users = $_SESSION['username'];
$email = $_SESSION['email_address'];
if(!$_POST['message']) {
echo 'Error ! : No message entered';
die;
}
// 2. Strip unwanted HTML
$message = strip_tags($_POST['message'], '');
$author = $users;
// 3. Make sure messages and names aren't too long
$message_length = strlen($message);
$author_length = strlen($author);
if($message_length > 500) {
echo "Error ! : Your message was too long, messages must be less than 500 chars";
die;
}
if($author_length > 500) {
echo "Error ! : Your name was too long, names must be less than 500 chars";
die;
}
// 4. Add it to our database.
// If the script hasn't died yet due to an error in the inputted data
// we need to add the data to the database
// Lets connect to our database.
mysql_connect($db_host,$db_user,$db_password) or die(mysql_error());
// Select the database.
mysql_select_db($db_name) or die(mysql_error());
// Lets define the date format we want to enter to our database
// go here for more details
// http://www.php.net/manual/en/function.date.php
$date = date("h:i A dS M");
// This will produce 11:02 25th Aug
// Set the query as $query
$query = "INSERT INTO shoutbox (message, author, email, date, ip)
VALUES ('$message','$author','$email','$date','$_SERVER[REMOTE_ADDR]')";
mysql_query($query);
mysql_close();
// Show thanks message and take them back to the main shoutbox
?>
<script>
window.location="shoutbox.php"
</script>
<?
// If they haven't submitted a post, we want to :
// 1. Show the latest shouts
// 2. Show the shout post form
} else {
// 1. Show the latest shouts
// Lets connect to our database.
mysql_connect($db_host,$db_user,$db_password) or die(mysql_error());
// Select the database.
mysql_select_db($db_name) or die(mysql_error());
// Set the query as $query, and get the last 6 posts.
$query = "SELECT message, author, email, date, ip
FROM shoutbox order by id DESC LIMIT 6";
$result = mysql_query($query);
echo "<table border='2' align='center' cellpadding='0' cellspacing='0' style='border-collapse: collapse' bordercolor='#000000' width='100%'>";
while($r=mysql_fetch_array($result))
{
// To modify the appearance, edit this :
echo "
<TR>
<TD><font size='3'>
<b><font face='Arial'> </font></font><font face='Arial'><font size='2'>
<A HREF=\"mailto:$r[email]\">
$r[author]</A> says:</b></font></font><font face='Arial' size='2'></font>
<font size='2' color='red' face='Comic Sans MS'><b><p align='center'>$r[message]</p></b></font>
</TR>";
}
echo "</TABLE>";
// 2. Show the shout post form
?>
<p align='center'><font face='Arial' color='#0000FF'><b>
<?
if(!$_SESSION['first_name']) {
echo "You must be logged in to write a message!<br><a href=\"login_form.html\">Log In</a> | <a href=\"join_form.html\">Register</a>";
} else {
echo "
<FORM METHOD=POST ACTION='shoutbox.php'><br>
<table border='1' cellpadding='0' cellspacing='0' style='border-collapse: collapse' bordercolor='#111111' width='142' align='center' id='AutoNumber1'>
<TR>
<TD width='51'><b><font size='1' face='Arial' color='#0000FF'>Message :</font></b></TD>
<TD width='142'><INPUT TYPE='text' NAME='message' size='17'></TD>
</TR>
<TR>
<TD width='51'>
<p align='center'><font face='Comic Sans MS' color='#0000FF'><b>TiG</b></font></TD>
<TD width='142'><p align='center'><INPUT TYPE='submit' name='submit' value='Post!'></p></TD>
</TR>
</TABLE>
</FORM>
<a href="logout.php">Log Out</a> | Change Password";
}
}
?>
<?php
session_start(); //start session
// You just need to configure these 4 variables to match your server.
$db_host = "localhost"; // mySQL database host
$db_user = "***"; // mySQL database user
$db_password = "*******"; // mySQL database password
$db_name = "****"; // the name of your mySQL database
if($_POST['submit']) {
// 1. Validate it, by checking all the form inputs were filled in
$users = $_SESSION['username'];
$email = $_SESSION['email_address'];
if(!$_POST['message']) {
echo 'Error ! : No message entered';
die;
}
// 2. Strip unwanted HTML
$message = strip_tags($_POST['message'], '');
$author = $users;
// 3. Make sure messages and names aren't too long
$message_length = strlen($message);
$author_length = strlen($author);
if($message_length > 500) {
echo "Error ! : Your message was too long, messages must be less than 500 chars";
die;
}
if($author_length > 500) {
echo "Error ! : Your name was too long, names must be less than 500 chars";
die;
}
// 4. Add it to our database.
// If the script hasn't died yet due to an error in the inputted data
// we need to add the data to the database
// Lets connect to our database.
mysql_connect($db_host,$db_user,$db_password) or die(mysql_error());
// Select the database.
mysql_select_db($db_name) or die(mysql_error());
// Lets define the date format we want to enter to our database
// go here for more details
// http://www.php.net/manual/en/function.date.php
$date = date("h:i A dS M");
// This will produce 11:02 25th Aug
// Set the query as $query
$query = "INSERT INTO shoutbox (message, author, email, date, ip)
VALUES ('$message','$author','$email','$date','$_SERVER[REMOTE_ADDR]')";
mysql_query($query);
mysql_close();
// Show thanks message and take them back to the main shoutbox
?>
<script>
window.location="shoutbox.php"
</script>
<?
// If they haven't submitted a post, we want to :
// 1. Show the latest shouts
// 2. Show the shout post form
} else {
// 1. Show the latest shouts
// Lets connect to our database.
mysql_connect($db_host,$db_user,$db_password) or die(mysql_error());
// Select the database.
mysql_select_db($db_name) or die(mysql_error());
// Set the query as $query, and get the last 6 posts.
$query = "SELECT message, author, email, date, ip
FROM shoutbox order by id DESC LIMIT 6";
$result = mysql_query($query);
echo "<table border='2' align='center' cellpadding='0' cellspacing='0' style='border-collapse: collapse' bordercolor='#000000' width='100%'>";
while($r=mysql_fetch_array($result))
{
// To modify the appearance, edit this :
echo "
<TR>
<TD><font size='3'>
<b><font face='Arial'> </font></font><font face='Arial'><font size='2'>
<A HREF=\"mailto:$r[email]\">
$r[author]</A> says:</b></font></font><font face='Arial' size='2'></font>
<font size='2' color='red' face='Comic Sans MS'><b><p align='center'>$r[message]</p></b></font>
</TR>";
}
echo "</TABLE>";
// 2. Show the shout post form
?>
<p align='center'><font face='Arial' color='#0000FF'><b>
<?
if(!$_SESSION['first_name']) {
echo "You must be logged in to write a message!<br><a href=\"login_form.html\">Log In</a> | <a href=\"join_form.html\">Register</a>";
} else {
echo "
<FORM METHOD=POST ACTION='shoutbox.php'><br>
<table border='1' cellpadding='0' cellspacing='0' style='border-collapse: collapse' bordercolor='#111111' width='142' align='center' id='AutoNumber1'>
<TR>
<TD width='51'><b><font size='1' face='Arial' color='#0000FF'>Message :</font></b></TD>
<TD width='142'><INPUT TYPE='text' NAME='message' size='17'></TD>
</TR>
<TR>
<TD width='51'>
<p align='center'><font face='Comic Sans MS' color='#0000FF'><b>TiG</b></font></TD>
<TD width='142'><p align='center'><INPUT TYPE='submit' name='submit' value='Post!'></p></TD>
</TR>
</TABLE>
</FORM>
<a href="logout.php">Log Out</a> | Change Password";
}
}
?>