Page 1 of 1
dun want to have the same email address..how?
Posted: Fri Apr 16, 2004 1:02 am
by joyce
hi, I got some problem in my php.
I dun want to have the same e-mail address in my guestbook.
So i create the error...
$error = "select email from guestbook where email = ('".$email."');";
if (!$error)
(
echo 'Error: Email address already exist.';
exit;
}
but this is not working. When i run in the localhost, the got error come our like this..
Parse error: parse error, unexpected T_ECHO in C:\Program Files\Apache Group\Apache2\htdocs\sign_guestbook.php on line 43
Can i know how to slove the problem...
Posted: Fri Apr 16, 2004 1:07 am
by Steveo31
Code: Select all
$error = "select email from guestbook where email = ('".$email."');";
if (!$error)
{
echo 'Error: Email address already exist.';
exit;
}
Posted: Fri Apr 16, 2004 1:20 am
by joyce
hi,
I change already.
But the email address still run out the same Email address when i run the localhost and never put the error out.
How?
Posted: Fri Apr 16, 2004 3:15 am
by vigge89
um, are you querying that before you check it?
also, i've never seen parentheses around the value, what's that for?
Code: Select all
<?php
$query_error = mysql_query ("SELECT `email` FROM `guestbook` WHERE `email` = '".$email."';";
### not sure if this is needed, i'm not sure...
$error = mysql_fetch_row ($query_error);
if (!$error) {
echo 'Error: Email address already exist.';
exit;
}
?>
Posted: Wed May 12, 2004 2:22 pm
by patrikG
joyce, please don't double-post.
Posted: Wed May 12, 2004 3:05 pm
by launchcode
Joyce - it's far quicker (and easier!) to do the following when checking if a value already exists:
Code: Select all
$query = "SELECT COUNT(*) AS hits FROM guestbook WHERE email = '$email'";
// Query the DB here
$hits = mysql_result($result, 0, 'hits');
if ($hits > 0)
{
echo "Sorry email address already exists";
}
Posted: Wed May 12, 2004 5:04 pm
by PrObLeM
you can do this too so it stops the script "dead in its tracks"
Code: Select all
if ($hits > 0)
{
die("Sorry email address already exists");
}
Posted: Wed May 12, 2004 5:59 pm
by launchcode
You can, but that's not exactly going to be very friendly to the user - not to mention it'll never finish off any HTML required to close the page neatly.
die() should only really ever be used on development servers, there's no need for it in a live environment.