Homemade Guestbook
Posted: Wed Sep 17, 2008 12:01 pm
I made a guestbook, in it you can insert "name", "mail", "homepage" and "text"
Where name and text are required through(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($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
)
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>";
}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>";}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