So, it's cheesy and kinda dumb, but what more do you want for a free hour on a random Thursday? At least I participated.
Official Cougar Calculator. Will you be my prey?
31 Replies - 11319 Views - Last Post: 01 July 2010 - 06:46 AM
#32
Re: Week #22: PHP
Posted 01 July 2010 - 06:46 AM
numberwhun, on 14 June 2010 - 08:35 AM, said:
@josh06 Will you be posting the code for the guest book or keeping it to yourself? Just curious.
Regards,
Jeff
Regards,
Jeff
Oh god I forgot about posting my code.
Here you go
index.php
<?php
// Index page of guestbook site.
session_start();
session_register('msg');
require('includes/db.php');
$title = 'Welcome to The Guestbook';
$h1 = 'Welcome to The Guestbook';
$js = true;
include('includes/head.htm');
?>
<br />
Welcome! This is just a small website to leave a message on. Just speak your mind :D/><br />
<b>Beware!</b> - Freedom of speech is allowed - but if abuse of any kind is submitted, your IP address may be reported
to the appropiate authorities.
<br /><br />
<b><?php echo $_SESSION['msg']; ?></b><br />
<?php $_SESSION['msg'] = ''; ?><br />
<b><a href='#' id='opnmsg'>Post something?</a></b>
<br /><br />
<div id='msgbox'>
<b><a href='#' id='hdemsg'>Hide?</a></b><br />
<form name='msg' action='pstmsg.php' method='post'>
<b>Name: </b><br /><input type='text' name='nme' maxlength='45' /><br />
<b>Message: </b><br />
<textarea name='message' rows='4' cols='40'>What's on your mind?</textarea><br />
<input type='submit' value='Post!' /> - <b>IP: </b><?php echo $_SERVER['REMOTE_ADDR']; ?>
<input type='hidden' value="<?php echo $_SERVER['REMOTE_ADDR'];?>" name='ip' />
<input type='hidden' name='date' value="<?php echo date('d/m/Y G:i');?>" />
</form>
</div>
<br />
<h1>Messages below:</h1>
<br /><br />
<div id='messages'>
<?php
$msgsql = 'SELECT * FROM posts ORDER BY date DESC';
$msgq = mysql_query($msgsql) or die(mysql_error());
while($row = mysql_fetch_array($msgq)){
echo '<b>Message: </b><br />' . $row['message'];
echo '<br /><br />';
echo '<b>Posted by: </b>' . $row['name'] . ' on ' . $row['date'];
echo '<br /><br /><hr><br />';
}
?>
</div>
<?php
include('includes/foot.htm');
?>
postmsg.php
<?php
session_start();
session_register('msg');
require('includes/db.php');
if($_POST['nme'] == ''){
$_SESSION['msg'] = 'You did not enter your name / message';
header('Location: index.php');
exit;
}else{
// Get data and add it to the database
$name = mysql_real_escape_string($_POST['nme']);
$msg = nl2br($_POST['message']);
$ip = $_POST['ip'];
$date = $_POST['date'];
$insql = 'INSERT INTO posts(name,message,ip,date) VALUES("' . $name . '","' . $msg . '","' . $ip . '","' . $date . '")';
mysql_query($insql) or die(mysql_error());
$_SESSION['msg'] = 'Thank you for posting your message :D/>';
header('Location: index.php');
exit;
}
?>
The rest is HTML and CSS which is boring (:
|
|

New Topic/Question
Reply






MultiQuote



|