Jump to content

GUESTBOOKS


dag_10
 Share

Recommended Posts

Use a combo of PHP and MySQL, you cant just make one out of no where thats custom!EDIT: I need some exp so ill try to make one.Ok! here it is (I know its not too good but im trying to make it better, will add an admin area and edit options).guestbook.php

<html><body><?phpif(!isset($_POST['post!']){?><form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST"><center>Post on my guest book</center>Your name:<input type="text" name="name" maxlenth="20"><br><input type="hidden" name="date" value="<?php echo date("n/j/y g:i:s A"); ?>">Your post:<br><textarea name="post" cols="50" rows="6" wrap="virtual">Post here</textarea><br><input type="submit" value="post!"></form><?php    }else{/* if the "submit" variable exists, the form has been submitted - look for and process form data *///put into table GBentries//set database variables, connect to mysqlinclude('config.php');//select databasemysql_select_db($db) or die ("Something is wrong!"); //make query to get rows$query = "INSERT INTO `GBentries` VALUES (" . $_POST['name'] . ", " . $_POST['date'] . ", " . $_POST['post'] . ")";//execute query$result = mysql_query($query) or die();//free result set memorymysql_free_result($result);//close connectionmysql_close($connection); }?><?php//set database variables, connect to mysqlinclude('config.php');//select databasemysql_select_db($db) or die ("Something is wrong!"); //make query to get rows$query = "SELECT * FROM `GBentries`";//execute query$result = mysql_query($query) or die();//see if there are any rowsif (mysql_num_rows($result) > 0) {   //there are rows, print them   echo "<table cellpading="5" border="2">";   while($row = mysql_fetch_row($result)) {	echo "<tr>";	echo "<td>Name:" . $row[0] . "</td>";	echo "<td>Date posted:" . $row[1] . "</td>";	echo "<td>Post:" . $row[2] . "</td>";	echo "</tr>";   }   echo "</table>";}else {   //no post yet   //put a table that says no post yet   echo "<table cellpading="5" border="2">";   echo "<tr>";   echo "<td>Sorry, No post in this guestbook yet!</td>";   echo "</tr>";   echo "</table>";}//free result set memorymysql_free_result($result);//close connectionmysql_close($connection); ?></body></html>

You may need to edit some things (like make a config.php) and other smal bugs and feel free to use this!Also post things that you think would make it better! Thanks!-reportingsjr-

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...