ManyCodes.com – codes & scripts Get free programming codes and tutorials!

13Feb/102

How to add a simple guest book to your site

So How to add a simple guest book to your site? The code below will help visitors to your site to read your guestbook entries and post a message of their own. Very simple setup, only requires you to change 4 settings. This code uses MySQL to store the entries.

<?php
/**
* Create the table in your MySQL database:
*
* CREATE TABLE guests (
*   id int(10) NOT NULL auto_increment,
*   name varchar(50) NOT NULL,
*   message varchar(255) NOT NULL,
*   date timestamp(14) NOT NULL,
*   PRIMARY KEY (id)
* )
*
* Change the database login settings to your own
*
* The script is now ready to run
*/
// Change these to your own database settings
$host = "localhost";
$user = "username";
$pass = "password";
$db = "database";

mysql_connect($host, $user, $pass) OR die ("Could not connect to the server.");
mysql_select_db($db) OR die("Could not connect to the database.");
$name = stripslashes($_POST['txtName']);
$message = stripslashes($_POST['txtMessage']);

if (!isset($_POST['txtName'])) {
$query = "SELECT id, name, message, DATE_FORMAT(date, '%D %M, %Y @ %H:%i') as newdate FROM guests ORDER BY id DESC";
$result = mysql_query($query);
while ($row = mysql_fetch_object($result)) {
?>

<p><strong><?php echo $row->message; ?></strong>

<br />Posted by <?php echo $row->name; ?> on <?php echo $row->newdate; ?></p>

<?php
     }
?>

<p>Post a message</p>

<form method="post" action="<?php echo $_SERVER['REQUEST_URI']; ?>">
<p><label for="txtName">Name:</label><br />
<input type="text" title="Enter your name" name="txtName" /></p>
<p><label for="txtMessage">Your message:</label><br />
<textarea title="Enter your message" name="txtMessage"></textarea></p>
<p><label title="Send your message">
<input type="submit" value="Send" /></label></p>
</form>

<?php
}
else {
// Adds the new entry to the database
$query = "INSERT INTO guests SET message='$message', name='$name', date=NOW()";
$result = mysql_query($query);

// Takes us back to the entries
$ref = $_SERVER['HTTP_REFERER'];
header ("Location: $ref");
}

?> 

The code above is referenced from http://www.totallyphp.co.uk

Tagged as: , , , , , , 2 Comments
28Jul/090

How to make the text dance in the status bar of the browser on which your site is opened

Here is how you can make the text dance in the status bar of the browser on which your site is opened.

Put the code below within your site's source code. If you dont know how to implement this code into your site, please goto how to implement the code to your website

Code:

<!-- this script is from www.manycodes.com -->

<!--   DESCRIPTION:  This will make your text bounce in the
status bar of the browser.

 INSTRUCTIONS:  Place this script in the HEAD tags of
your webpage.  Then place the text you want to be bounced in
the area that says, "YOUR MESSAGE HERE".

 FUNCTIONALITY: Works in both Netscape & IE.
-->

<SCRIPT LANGUAGE="JavaScript">
//Modified by CoffeeCup Software
//This code is Copyright (c) 1997 CoffeeCup Software
//all rights reserved. License is granted to a single user to
//reuse this code on a personal or business Web Site.



var yourtext = "* YOUR MESSAGE HERE! *";
var wedge1="                        ";
var wedge2="                        ";
var message1=wedge1+yourtext+wedge2;
var dir = "lside";
var speed = 50;

function bouncey() {

 if (dir == "lside") {
 message2=message1.substring(2,message1.length)+"  ";
 window.status=message2;
 setTimeout("bouncey();",speed);
 message1=message2;

 if (message1.substring(0,1) == "*") {
 dir="rside";
 }
 }

 else {
 message2="  "+message1.substring(0,message1.length-2);
 window.status=message2;
 setTimeout("bouncey();",speed);
 message1=message2;
 if (message1.substring(message1.length-1,message1.length) == "*") {
 dir="lside";
 }
 }
}

// -- End Hiding Here -->
</SCRIPT>

<body onLoad="bouncey()">
<font face="Tahoma"><a target="_blank" href="http://www.manycodes.com/category/java/javascript-codes/"><span style="font-size: 8pt; text-decoration: none">JavaScript Free Code</span></a></font>