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
13Feb/100

How to make an e-mail contact form on your website?

This is a simple form mail PHP script that displays a contact form to enable visitors to your site to send the website administrator a message via email. Built in security will prevent spammers hijacking it from another domain.

<?php
/**
* Change the email address to your own.
*
* $empty_fields_message and $thankyou_message can be changed
* if you wish.
*/

// Change to your own email address
$your_email = "you@example.com";

// This is what is displayed in the email subject line

// Change it if you want
$subject = "Message via your contact form";

// This is displayed if all the fields are not filled in
$empty_fields_message = "<p>Please go back and complete all the fields in the form.</p>";

// This is displayed when the email has been sent
$thankyou_message = "<p>Thankyou. Your message has been sent.</p>";

// You do not need to edit below this line

$name = stripslashes($_POST['txtName']);
$email = stripslashes($_POST['txtEmail']);
$message = stripslashes($_POST['txtMessage']);

if (!isset($_POST['txtName'])) {
?>

<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="txtEmail">Email:</label><br />
<input type="text" title="Enter your email address" name="txtEmail" /></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
}

elseif (empty($name) || empty($email) || empty($message)) {

echo $empty_fields_message;
}

else {
// Stop the form being used from an external URL
// Get the referring URL
$referer = $_SERVER['HTTP_REFERER'];

// Get the URL of this page
$this_url = "http://".$_SERVER['HTTP_HOST'].$_SERVER["REQUEST_URI"];

// If the referring URL and the URL of this page don't match then

// display a message and don't send the email.
if ($referer != $this_url) {
echo "You do not have permission to use this script from another URL.";
exit;
}

// The URLs matched so send the email
mail($your_email, $subject, $message, "From: $name <$email>");

// Display the thankyou message
echo $thankyou_message;
}
?>

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

22Jul/090

How to add Fireworks effects with different colors to your webpage

Here is how you can add Fireworks effects with different colors to your webpage.

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 -->
<body bgcolor='#000000' >
<!-- Start of Fireworks -->
<script language="JavaScript">
<!--  IE4+, NS4+, NS6 Fireworks script by kurt.grigg@virgin.net
CL=new Array('#ff0000','#00ff00','#ffffff','#ff00ff','#ffa500','#ffff00','#00ff00','#ffffff','#ff00ff')
CL2=new Array('#ffa500','#00ff00','#FFAAFF','#fff000','#fffffF')
Xpos=130;
Ypos=130;
I='#00ff00';
C=0;
S=5;
H=null;
W=null;
Y=null;
NS4=(document.layers);
NS6=(document.getElementById&&!document.all);
IE4=(document.all);
A=14;
E=120;
L=null;
if (NS4){
for (i=0; i < A; i++)
document.write('<LAYER NAME="nsstars'+i+'" TOP=0 LEFT=0 BGCOLOR='+I+' CLIP="0,0,2,2"></LAYER>');
}
if (NS6){
window.document.body.style.overflow='hidden';
for (i=0; i < A; i++)
document.write('<div id="ns6stars'+i+'" style="position:absolute;top:0px;left:0px;height:2px;width:2px;font-size:2px;background:'+I+'"></div>');
}
if (IE4){
document.write('<div id="ie" style="position:absolute;top:0px;left:0px"><div style="position:relative">');
for (i=0; i < A; i++)
document.write('<div id="iestars" style="position:absolute;top:0;left:0;width:2px;height:2px;background:'+I+';font-size:2px"></div>');
document.write('</div></div>');
}
function Fireworks(){
H=(NS4||NS6)?window.innerHeight:window.document.body.clientHeight;
W=(NS4||NS6)?window.innerWidth:window.document.body.clientWidth;
Y=(NS4||NS6)?window.pageYOffset:window.document.body.scrollTop;
for (i=0; i < A; i++){
if (IE4)L=iestars[i].style;
if (NS4)L=document.layers["nsstars"+i];
if (NS6)L=document.getElementById("ns6stars"+i).style;
var F = CL[Math.floor(Math.random()*CL.length)];
var RS=Math.round(Math.random()*2);
L.top = Ypos + E*Math.sin((C+i*5)/3)*Math.sin(C/100)
L.left= Xpos + E*Math.cos((C+i*5)/3)*Math.sin(C/100)
if (C < 110){
 if (NS4){L.bgColor=I;L.clip.width=1;L.clip.height=1}
 if (IE4||document.getElementById)
 {L.background=I;L.width=1;L.height=1;L.fontSize=1}
 }
else{
 if (NS4){L.bgColor=F;L.clip.width=RS;L.clip.height=RS}
 if (IE4||document.getElementById){L.background=F;L.width=RS;L.height=RS;L.fontSize=RS}
 }
}
if (C > 220){
 C=0;
 var NC = CL2[Math.floor(Math.random()*CL2.length)];
 I=NC;
 E=Math.round(100+Math.random()*90);
 Ypos = E+Math.round(Math.random()*(H-(E*2.2)))+Y;
 Xpos = E+Math.round(Math.random()*(W-(E*2.2)));
}
C+=S;
setTimeout("Fireworks()",10);
}
Fireworks();
// -->
</script>
<!-- End of Fireworks -->
<pre><font face="Tahoma"><a target="_blank" href="http://www.manycodes.com/"><span style="font-size: 8pt; text-decoration: none">JavaScript Free Code</span></a></font></pre>
22Jul/095

Here is how you can implement the code to your website

Here is how you can implement the code to your website

JavaScript Free Code