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
some_new_guy
Forum Newbie
Posts: 10 Joined: Thu Mar 25, 2004 10:58 am
Post
by some_new_guy » Thu Mar 25, 2004 5:58 pm
Can anyone help me with this code? The form has a variable for an email which is "enterEmail", and I want it to check my database if the email has already been entered. This is what I came up with, but it has failed so far. Thanks in advance...
Code: Select all
<?php
$msg = "";
$user = "mydatabase";
$password = "";
$db = "whatever";
$link = mysql_connect("localhost", $user, $password);
if (!$link) die ("cant connect to mysql");
mysql_select_db($db, $link) or die ("cannot connect");
$query "SELECT email FROM mailinglist WHERE email='$enterEmail'";
mysql_query($query, $link) or die (mysql_error());
$result=mysql_query($query);
$count=mysql_num_rows($result);
if ($count > 0){
print "&EmailStatus=You have already entered."
}
else{
print "&loading=NO";
}
?>
markl999
DevNet Resident
Posts: 1972 Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)
Post
by markl999 » Thu Mar 25, 2004 6:00 pm
Try..
Code: Select all
<?php
$msg = '';
$user = 'mydatabase';
$password = '';
$db = 'whatever';
$link = mysql_connect('localhost', $user, $password);
if (!$link) die ("cant connect to mysql");
mysql_select_db($db) or die ('cannot connect');
$query = "SELECT email FROM mailinglist WHERE email='{_POST['enterEmail']}'";
$result = mysql_query($query) or die (mysql_error());
if(mysql_num_rows($result)){
echo '&EmailStatus=You have already entered.'
} else {
echo '&loading=NO';
}
?>
tim
DevNet Resident
Posts: 1165 Joined: Thu Feb 12, 2004 7:19 pm
Location: ohio
Post
by tim » Thu Mar 25, 2004 6:01 pm
whats the problem/error?
Steveo31
Forum Contributor
Posts: 416 Joined: Sun Nov 23, 2003 9:05 pm
Location: San Jose CA
Post
by Steveo31 » Thu Mar 25, 2004 6:02 pm
Here's what I have for a checker:
Code: Select all
<?php
$result = mysql_query("SELECT foo FROM bar");
while($line = mysql_fetch_array($result, MYSQL_ASSOC)){
if($varToCheck== $line['name']){
echo "You are already registered.";
exit;
}
}
some_new_guy
Forum Newbie
Posts: 10 Joined: Thu Mar 25, 2004 10:58 am
Post
by some_new_guy » Thu Mar 25, 2004 6:03 pm
Parse error: parse error in script.php on line 17
markl999
DevNet Resident
Posts: 1972 Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)
Post
by markl999 » Thu Mar 25, 2004 6:05 pm
echo '&EmailStatus=You have already entered.'; <-- i forgot the ; in mine
tim
DevNet Resident
Posts: 1165 Joined: Thu Feb 12, 2004 7:19 pm
Location: ohio
Post
by tim » Thu Mar 25, 2004 6:09 pm
lol a simple fix, the ; hopefully.
anyway, mark is to quick on his replies.
i am going to call mark 'shooter' from now on.
markl999
DevNet Resident
Posts: 1972 Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)
Post
by markl999 » Thu Mar 25, 2004 6:13 pm
That's what my girlfriend calls me
phice
Moderator
Posts: 1416 Joined: Sat Apr 20, 2002 3:14 pm
Location: Dallas, TX
Contact:
Post
by phice » Thu Mar 25, 2004 6:26 pm
d3ad1ysp0rk
Forum Donator
Posts: 1661 Joined: Mon Oct 20, 2003 8:31 pm
Location: Maine, USA
Post
by d3ad1ysp0rk » Thu Mar 25, 2004 7:57 pm
markl999 wrote: That's what my girlfriend calls me
hmm..
mark n tim sittin in a tree, c - o - d - i - n - g
*giggles*
Goowe
Forum Commoner
Posts: 94 Joined: Mon Mar 15, 2004 9:51 am
Location: Southeast Alaska
Post
by Goowe » Thu Mar 25, 2004 8:02 pm
tim
DevNet Resident
Posts: 1165 Joined: Thu Feb 12, 2004 7:19 pm
Location: ohio
Post
by tim » Thu Mar 25, 2004 9:08 pm
its to the point where if I see mark has contributed, I hit refresh to check if hes posted or not before I post my reply. Which usually he hasssssss posted the/a solution.
cant complain, i've learned alot from him just by reading his post. This board is lucky to have a person as him.
kudos to shooter
some_new_guy
Forum Newbie
Posts: 10 Joined: Thu Mar 25, 2004 10:58 am
Post
by some_new_guy » Fri Mar 26, 2004 2:13 am
This is the code that won't give me the parse error, but it also will not give the correct response. I've entered an email that IS in the database, but am getting the else statement when this comes up.
Code: Select all
<?php
$msg = "";
$user = "myDatabase";
$password = "";
$db = "test";
$link = mysql_connect("localhost", $user, $password);
if (!$link) die ("cant connect to mysql");
mysql_select_db($db, $link) or die ("cannot connect");
$query = "SELECT email FROM mailinglist WHERE email='enterEmail'";
$result = mysql_query($query) or die (mysql_error());
if(mysql_num_rows($result)){
echo "&EmailStatus=You have already entered.";
}
else { print "&loading=NO";
}
?>
Could the problem be that the email field in my database is the second column? Does this make sense? I'm stumped.
Could it be the @ symbol screwing up the query in the database?
This is all new to me. My apologies if I seem incompetent.
some_new_guy
Forum Newbie
Posts: 10 Joined: Thu Mar 25, 2004 10:58 am
Post
by some_new_guy » Fri Mar 26, 2004 2:35 am
$query = "SELECT email FROM mailinglist WHERE email='$enterEmail'";
Guess who forgot the $
Sometimes it's the little things that get you. Thank you guys for your help! I'm sure I'll be back...