Guestbooks

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Chocolate_Raindrop
Forum Newbie
Posts: 11
Joined: Thu May 20, 2004 6:07 pm
Location: Alabama
Contact:

Guestbooks

Post by Chocolate_Raindrop »

I'm new at this so I really don't know what I'm doing. I'm trying to get the information from a form to post to the bottom of the page. Can anyone please help me. :cry:
Unipus
Forum Contributor
Posts: 409
Joined: Tue Aug 26, 2003 2:06 pm
Location: Los Angeles, CA

Post by Unipus »

Recommend you go somewhere like http://www.w3schools.com/php/default.asp and do some tutorials. There's plenty of them.
User avatar
tim
DevNet Resident
Posts: 1165
Joined: Thu Feb 12, 2004 7:19 pm
Location: ohio

Post by tim »

read about the GET method, and use $PHP_SELF as the form action.

use isset to determine if the values have been sent thru the form, if they have.
echo em out

$_GET['username'];

etc, that should be enough info for what you want
?>
User avatar
doggy
Forum Commoner
Posts: 80
Joined: Tue Dec 09, 2003 5:01 am
Location: South Africa

Post by doggy »

Chocolate_Raindrop if you want you can rent a programer like myself to do the project for you. Go here for more information viewtopic.php?t=21799 . I know its open source and for free and every thing but a man must eat. Enjoy
User avatar
tim
DevNet Resident
Posts: 1165
Joined: Thu Feb 12, 2004 7:19 pm
Location: ohio

Post by tim »

doggy wrote:Chocolate_Raindrop if you want you can rent a programer like myself to do the project for you. Go here for more information viewtopic.php?t=21799 . I know its open source and for free and every thing but a man must eat. Enjoy
you make it sound like us /programmers/ are machines, lol. You can rent em?

You can /contract/ me to complete the projet for you with a cash transfer for the services
User avatar
doggy
Forum Commoner
Posts: 80
Joined: Tue Dec 09, 2003 5:01 am
Location: South Africa

Post by doggy »

Sorry i did use the wrong words , I show a site that had rent a programer and it sicked in my brian, sorry tim didn`t to sound like you programers are like machines that you can just rent.
User avatar
tim
DevNet Resident
Posts: 1165
Joined: Thu Feb 12, 2004 7:19 pm
Location: ohio

Post by tim »

lol no problem

just tapping in my .02
Chocolate_Raindrop
Forum Newbie
Posts: 11
Joined: Thu May 20, 2004 6:07 pm
Location: Alabama
Contact:

Please help fix this problem for me.

Post by Chocolate_Raindrop »

Can someone look at my website and tell me what I'm doing wrong. I got this script from Hitech-Scripts.com and it works. Well at least that's what I thought. When I tested it out all the information posted but when I wanted to add another post to the top or bottom of the page it doesn't show the post that was previously entered. My web address is http://www.icdat.cc/cdrop/index2.html
d3ad1ysp0rk
Forum Donator
Posts: 1661
Joined: Mon Oct 20, 2003 8:31 pm
Location: Maine, USA

Post by d3ad1ysp0rk »

Looks like it's not actually being saved.

Too bad we have no idea what the code looks like so you're outta luck with this one.. unlesss.. oh ya, you post some code ;)
Chocolate_Raindrop
Forum Newbie
Posts: 11
Joined: Thu May 20, 2004 6:07 pm
Location: Alabama
Contact:

Thank you for helping me

Post by Chocolate_Raindrop »

This is the php code for my guestbook.

Code: Select all

<?php

//***********************************************************
//*
//* guestbook.php - a Guestbook script
//* (c) Hitech Scripts 2003
//* For more information, visit http://www.hitech-scripts.com
//*
//***********************************************************

$filename = "guestbook.html";
$title = "Welcome To My Chocolate Factory Guestbook";
$store_ip = 0;

error_reporting(0);

if (($action == "sign") || ($action == "post"))  {
   $header = get_header();
   echo $header;
}

if ($action == "sign")
{
   $form_text = get_form();
   echo $form_text;
}

if ($action == "post")
{
   $date = date ("l dS of F Y h:i:s A");

   $name = htmlentities($name);
   
   if ($site_url != "")   {
      $site_url = htmlentities($site_url);
      $url_checker = explode("http://", $site_url);
   
      if (!IsSet($url_checker[1])) {
		 $site_url = "http://$site_url";
	  } else {
		 $site_url = "$site_url";
	  }
   } 
   else {
	  $site_url = "none";
   }

   if ($site_url <> "none") {
      $name = '<a target=_blank href="' . $site_url . '">' . $name . "</a>";
   }
      
   if ($email != "")   {
      $email = htmlentities($email);
      $email_checker = explode("@", $email);
      if (!IsSet($email_checker[1])) {
         $email = "none";			
      } else {
	     //email checked
      }
   }
   
   $ip_address = getIP();  	
   $location = htmlentities($location);
   
   $comments = htmlentities($comments);
   $comments = parse_smiles($comments, array(':)' => "biggrin-c.gif", ':?' => "confused-c.gif", 'B)' => "cool-c.gif", ':(' => "cry.gif", 'F:' => "frown-c.gif", 'D)' => "shiny.gif", ')D' => "smile-c.gif", ';)' => "wink-c.gif"));
   
   if (is_writable($filename)) {
      $file = @fopen($filename, "r");
      $result = fread($file, filesize($filename));
      fclose($file);	  
   }
   else  {
      $footer = get_footer();
	  
      $file = @fopen($filename, "w");
      $guest_text = $header . '<!--Guestbook_start-->  <!--Guestbook_end-->' . $footer;
	  fwrite($file, $guest_text);
      fclose($file);
      chmod ($filename, 0775);
	  $result = $guest_text; 
   }
    
   $checker = explode("<!--Guestbook_start-->", $result);
   
   $msg = get_message($date, $name, $email, $ip_address, $location, $comments);
   $guest_text = $checker[0] . '<!--Guestbook_start-->' . $msg . $checker[1]; 
      
   $file = @fopen($filename, "w");
   fwrite($file, $guest_text);
   fclose($file);
   chmod ($filename, 0775);
   
   echo $msg;	
}

if (($action != "sign") && ($action != "post"))  {
   if (is_writable($filename)) {
      $file = @fopen($filename, "r");
      $result = fread($file, filesize($filename));
      fclose($file);	  
   
      echo $result;
   }
   exit;	  
}

$footer = get_footer();
echo $footer;

exit;
//-------------------------------------------------------------------------------------------------
function get_message($date, $name, $email, $ip_address, $location, $comments)   {
   $msg = '<!-- IP address - ' . $ip_address . ' -->
<br>
<br>
<table width="100%">
<tr>
       <td width="100"><b>Name:</b></td> 
       <td>' . $name . '</td>
</tr>
<tr>
       <td><b>Email:</b></td>
       <td>' . $email . '</td>
</tr>
<tr>
       <td><b>Location:</b></td>
       <td>' . $location . '</td>
</tr>
<tr>
       <td><b>Date:</b></td>
       <td>' . $date . '</td>
</tr>
<tr>
       <td colspan="2"><b>Comments:</b></td>
</tr>
<tr>
       <td colspan="2" align="left">' . $comments . '</td>
</tr>
<tr>
       <td colspan="2"><hr></td>
</tr>
</table>
</div>';

   return $msg;
}
//-------------------------------------------------------------------------------------------------
function get_form()     {
   $form_text = '<form action="guestbook.php" METHOD="POST">
<input name="action" type="hidden" value="post">
<table border="0" align="center">
<tr><td><font size="4">Name:</td><td><input name="name" size="48" type="text" value=""><br></td></tr>
<tr><td><font size="4">Email:</td><td><input name="email" size="48" type="text" value=""><br></td></tr>
<tr><td><font size="4">Site url:</td><td><input name="site_url" size="48" type="text" value=""><br>
<tr><td><font size="4">Location:</td><td><input name="location" size="48" type="text" value=""><br>
<tr><td valign="top"><font size="4">Comments:</td><td><textarea name="comments" rows="8" cols="36"></textarea>
<br><center>
<input value="Sign" type="submit">&nbsp;&nbsp;<input type="reset"></td>
</tr>
</table>
</form>
				 ';
  				 
   return $form_text;				 
}
//-------------------------------------------------------------------------------------------------
function get_header()   {
   global $title, $filename;
   
   $header = '<html>
<head>
	<title>' . $title . '</title>
</head>

<body bgcolor="#663300" text="#33000" link="#330000" alink="#330000" vlink="#330000">
<center><h1>' . $title . '</h1>
<table width="350">
<tr>
       <td align=center><a href="guestbook.php?action=sign">Sign to guestbook</a></td>
       <td align=center><a href="' . $filename . '">View guestbook</a></td>
</tr>
</table>

';
  
  return $header;
}
//-------------------------------------------------------------------------------------------------
function get_footer()   {
  $footer = '</center> <center>Powered by <a href="http://www.hitech-scripts.com">Hitech-scripts.com</a></center></body></html>';
  
  return $footer;
}
//-------------------------------------------------------------------------------------------------
function parse_smiles($msg, $parse_string='nil')
{  		 
   if (is_array($parse_string))
      {
         while (list($name, $parse_value) = each ($parse_string))
            {
               $parse_value1 = '<img src="smiles/'. $parse_value . '" width="17" height="17" border="0">';  
    	 $msg = str_replace($name, $parse_value1, $msg);
            }
     }
   return $msg;
}
//-------------------------------------------------------------------------------------------------
function getIP() 
{
   global $store_ip;
   
   $ip;
   if (getenv("HTTP_CLIENT_IP")) $ip = getenv("HTTP_CLIENT_IP");
   else if(getenv("HTTP_X_FORWARDED_FOR")) $ip = getenv("HTTP_X_FORWARDED_FOR");
   else if(getenv("REMOTE_ADDR")) $ip = getenv("REMOTE_ADDR");
   else $ip = "UNKNOWN";
   
   if ($store_ip == 0)   {  $ip = "unknown"; }
   return $ip;
}
//-------------------------------------------------------------------------------------------------

?>
feyd|use

Code: Select all

tags..[/color]
d3ad1ysp0rk
Forum Donator
Posts: 1661
Joined: Mon Oct 20, 2003 8:31 pm
Location: Maine, USA

Post by d3ad1ysp0rk »

uhh... look up feyd
Chocolate_Raindrop
Forum Newbie
Posts: 11
Joined: Thu May 20, 2004 6:07 pm
Location: Alabama
Contact:

Post by Chocolate_Raindrop »

I'm very new to php so i really don't know the lingo here. what's feyd?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Chocolate_Raindrop wrote:what's feyd?
me. :D he was talking to a post, which I already deleted..
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

looks like the code was written for register_globals being on.. additionally try removing the @ in front of the fopen calls... the script may not be able to open the files...
Chocolate_Raindrop
Forum Newbie
Posts: 11
Joined: Thu May 20, 2004 6:07 pm
Location: Alabama
Contact:

Post by Chocolate_Raindrop »

i removed the @ from all of the fopen but it still doesn't work.
Post Reply