dun want to have the same email address..how?

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
joyce
Forum Newbie
Posts: 6
Joined: Fri Apr 16, 2004 1:02 am

dun want to have the same email address..how?

Post 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...
Steveo31
Forum Contributor
Posts: 416
Joined: Sun Nov 23, 2003 9:05 pm
Location: San Jose CA

Post by Steveo31 »

Code: Select all

$error = "select email from guestbook where email = ('".$email."');";
if (!$error)
{
echo 'Error: Email address already exist.';
exit;
}
joyce
Forum Newbie
Posts: 6
Joined: Fri Apr 16, 2004 1:02 am

Post 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?
User avatar
vigge89
Forum Regular
Posts: 875
Joined: Wed Jul 30, 2003 3:29 am
Location: Sweden

Post 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;
}

?>
User avatar
patrikG
DevNet Master
Posts: 4235
Joined: Thu Aug 15, 2002 5:53 am
Location: Sussex, UK

Post by patrikG »

joyce, please don't double-post.
User avatar
launchcode
Forum Contributor
Posts: 401
Joined: Tue May 11, 2004 7:32 pm
Location: UK
Contact:

Post 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";
}
User avatar
PrObLeM
Forum Contributor
Posts: 418
Joined: Sun Mar 07, 2004 2:30 pm
Location: Mesa, AZ
Contact:

Post 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");
}
User avatar
launchcode
Forum Contributor
Posts: 401
Joined: Tue May 11, 2004 7:32 pm
Location: UK
Contact:

Post 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.
Post Reply