likely another simple question with a simple fix

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
some_new_guy
Forum Newbie
Posts: 10
Joined: Thu Mar 25, 2004 10:58 am

likely another simple question with a simple fix

Post by some_new_guy »

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";
}
?>
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

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';
}
?>
User avatar
tim
DevNet Resident
Posts: 1165
Joined: Thu Feb 12, 2004 7:19 pm
Location: ohio

Post by tim »

whats the problem/error?

8)
Steveo31
Forum Contributor
Posts: 416
Joined: Sun Nov 23, 2003 9:05 pm
Location: San Jose CA

Post by Steveo31 »

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 »

Parse error: parse error in script.php on line 17
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

echo '&EmailStatus=You have already entered.'; <-- i forgot the ; in mine :o
User avatar
tim
DevNet Resident
Posts: 1165
Joined: Thu Feb 12, 2004 7:19 pm
Location: ohio

Post by tim »

lol a simple fix, the ; hopefully.

anyway, mark is to quick on his replies.

i am going to call mark 'shooter' from now on.
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

That's what my girlfriend calls me :o
User avatar
phice
Moderator
Posts: 1416
Joined: Sat Apr 20, 2002 3:14 pm
Location: Dallas, TX
Contact:

Post by phice »

:x
Image Image
d3ad1ysp0rk
Forum Donator
Posts: 1661
Joined: Mon Oct 20, 2003 8:31 pm
Location: Maine, USA

Post by d3ad1ysp0rk »

markl999 wrote:That's what my girlfriend calls me :o
hmm..



mark n tim sittin in a tree, c - o - d - i - n - g

*giggles*


:D
Goowe
Forum Commoner
Posts: 94
Joined: Mon Mar 15, 2004 9:51 am
Location: Southeast Alaska

Post by Goowe »

:lol:
User avatar
tim
DevNet Resident
Posts: 1165
Joined: Thu Feb 12, 2004 7:19 pm
Location: ohio

Post by tim »

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 »

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 »

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