Saturday, March 19

my simple guestbook

"!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN""
"html"
"body"

"B"Please Sign Our Guestbook "/B""P"

"FORM METHOD="POST" ACTION="index.php""

"TABLE border="0" cellpadding="2" cellspacing="2" style="font: 11px verdana""

"TR"
"TD"
Full Name:
"/TD"

"TD"
"INPUT TYPE="text" NAME="name" value="""
"/TD"
"/TR"

"TR"
"TD"
Email Address
"/TD"
"TD"
"INPUT TYPE="text" NAME="email" value="""
"/TD"
"/TR"
"TR"
"TD colspan="2""
Message:"BR""TEXTAREA NAME="message" ROWS="3" COLS="35"""/TEXTAREA"
"/TD"
"/TR"
"TR"
"TD colspan="2""
"INPUT TYPE="submit" name="submit" value="Submit""
"/TD"
"/TR"
"/TABLE"
"/FORM"
"?php
//Connect to host, user, pwd
$con = mysql_connect("localhost","divya","prembharti");
if (!$con)
{ die('Could not connect: ' . mysql_error()); }

//connect to database
mysql_select_db("guestbook", $con);
//getting all query
$gname=$_POST[name] ;
$gemail= $_POST[email];
$gmessage= $_POST[message];
$gdate=date("Y-m-d");
$gtime=date("H:i:s");
//checking field filling condition
if (($gemail OR $gmessage OR $gname)=="")
{echo "Enter All three Fields.....!!";
}
//checking for correct email address
else if((strpbrk($gemail,"@"))==false)
{
echo "Please Correct your email address....!!";
}
else if((strpbrk($gemail,"."))==false)
{
echo "Please Correct your email address....!!";
}
//checking for ' character
else if((strpbrk($gmessage,"'"))==true)
{
echo "Please Don't use... (') character in your Message...!!";
}
else {
//Inserting all data
$sql="INSERT INTO gbt (Name,Email,Message,Date,Time) VALUES('$gname','$gemail','$gmessage','$gdate','$gtime')";
if (!mysql_query($sql,$con))
{ die('Error: ' . mysql_error()); }
}
//Getting all data and setting to descending order by Id
$getquery= mysql_query("SELECT * FROM gbt ORDER BY ID DESC");
//fetching data from sql
while($row=mysql_fetch_assoc($getquery))
{
$id= $row['ID'];
$name= $row['Name'];
$email=$row['Email'];
$message=$row['Message'];
$date=$row['Date'];
$time=$row['Time'];
//setting color for table
if($id%2)
$bgcolor = "#FFFFFF";
else
$bgcolor = "#e1e1e1";
//designing the table and printing the data...!!
echo "
"table bgcolor='$bgcolor'"
"tr"
"td"
"b" Posted by $name [$email] [$date : $time] "/b"

"/td"

"/tr"
"td"
".nl2br(strip_tags($message))."
"/td"
"tr"
"/tr"
"/table"
";
}
?"
"/body"
"/html"

No comments: