This is a simple guestbook code/script written from scratch. Just copy and paste but replace the server,username and password values to your own.
Note: You'll need a host with a php service for this to work - meaning it won't work here on blogger.
";
echo "" . $id['id'] . "." . $id['name'];
echo "said @" ;
echo "" . $id['date'] . ":
";
echo " ". "" . $id['msg'] . "
";
echo "
";
echo "
";
}
mysql_close($con);
?>
alert('Please put a name')";
die();
}
if(!$_POST[msg]){
echo "";
die();
}
filter_input(INPUT_POST, 'name', FILTER_SANITIZE_SPECIAL_CHARS); /*---sanitize inputs-----*/
filter_input(INPUT_POST, 'url', FILTER_SANITIZE_URL); /*---sanitize inputs-----*/
filter_input(INPUT_POST, 'msg', FILTER_SANITIZE_SPECIAL_CHARS); /*---sanitize inputs-----*/
$con = mysql_connect("server","username","password");
if(!$con){ /*----- verify connection -------*/
die("could not connect" . mysql_error());
}
mysql_select_db("database", $con); /*----- locate database --------*/
$sql="INSERT INTO post (name, url, msg)
VALUES
('$_POST[name]','$_POST[url]','$_POST[msg]')";
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
$time = mktime(date("h")+16,date("i")+14,0,date("m"),date("d"),date("Y"));
$result = mysql_query("SELECT id FROM post");
while($id = mysql_fetch_array($result)){ /*----- return array ------*/
$num = $id['id'];
}
echo $num;
$dt = date('MdY H:i',$time);
echo $dt;
$sql = "UPDATE post SET date='$dt' WHERE id=$num";
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
mysql_close($con);
echo "";
?>
No comments:
Post a Comment