Homemade Guestbook

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

Post Reply
User avatar
Thorbear
Forum Newbie
Posts: 3
Joined: Sun May 11, 2008 10:13 am
Location: Check my IP

Homemade Guestbook

Post by Thorbear »

I made a guestbook, in it you can insert "name", "mail", "homepage" and "text"
Where name and text are required through

Code: Select all

if(isset($_REQUEST['names']) && isset($_REQUEST['texts']))
{
 $names = $_REQUEST['names'];
 $emails = $_REQUEST['emails'];
 $homes = $_REQUEST['homes'];
 $texts = $_REQUEST['texts'];
 mysql_query("INSERT INTO `database`.`guestbook` (`id` ,`name` ,`email` ,`home` ,`date` ,`text`) VALUES (NULL , '$names', '$emails', '$homes', CURDATE() , '$texts');");
 echo "<p><b>Thank You</b></p>";
}
(at least I thought it would require name and text)

As you can see, the data is stored in a database, when writing this data to the screen I use icons to link mail and homepage.
However, these links also appear even if the user has typed in no data, I fixed this with some simple if sentences

Code: Select all

if ($email == NULL)
 {echo "<td>";}
else
 {echo "<td><a href=\"mailto:$email\"><img src=\"images/mail.jpg\" /></a>";}
if ($home == "http://")
 {echo "</td>";}
elseif ($home == NULL)
 {echo "</td>";}
else
 {echo "<a href=\"$home\"><img src=\"images/homep.jpg\" /></a></td>";}
($home == "http://" because "http://" is automatically in the sign form)

Now if someone write in "www.somepage.com" as their homepage, that will link to "http://thorbear.navhost.com/www.somepage.com" because it lacks the "http://".
My question is; what function can I use to detect wether "http://" is the first 7 chrs of the data or not? (for to add it if absent)

(and if anyone can tell me what I did wrong with the check for "name" and "text" too, that would be good :lol: )
Last edited by Thorbear on Wed Sep 17, 2008 12:20 pm, edited 1 time in total.
User avatar
jayshields
DevNet Resident
Posts: 1912
Joined: Mon Aug 22, 2005 12:11 pm
Location: Leeds/Manchester, England

Re: Homemade Guestbook

Post by jayshields »

Thorbear wrote:what function can I use to detect wether "http://" is the first 7 chrs of the data or not?
I only read that bit.

Code: Select all

if(substr($data, 0, 7) == 'http://') echo 'yep';
User avatar
Thorbear
Forum Newbie
Posts: 3
Joined: Sun May 11, 2008 10:13 am
Location: Check my IP

Re: Homemade Guestbook

Post by Thorbear »

jayshields wrote:
Thorbear wrote:what function can I use to detect wether "http://" is the first 7 chrs of the data or not?
I only read that bit.

Code: Select all

if(substr($data, 0, 7) == 'http://') echo 'yep';
Hehe, which is why I made that bold, but sometimes people want to know the details ;)

Anyway, that was exacly what I was looking for, thanks :)
Post Reply