Page 1 of 1

likely another simple question with a simple fix

Posted: Thu Mar 25, 2004 5:58 pm
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";
}
?>

Posted: Thu Mar 25, 2004 6:00 pm
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';
}
?>

Posted: Thu Mar 25, 2004 6:01 pm
by tim
whats the problem/error?

8)

Posted: Thu Mar 25, 2004 6:02 pm
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;
	}
}

Posted: Thu Mar 25, 2004 6:03 pm
by some_new_guy
Parse error: parse error in script.php on line 17

Posted: Thu Mar 25, 2004 6:05 pm
by markl999
echo '&EmailStatus=You have already entered.'; <-- i forgot the ; in mine :o

Posted: Thu Mar 25, 2004 6:09 pm
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.

Posted: Thu Mar 25, 2004 6:13 pm
by markl999
That's what my girlfriend calls me :o

Posted: Thu Mar 25, 2004 6:26 pm
by phice
:x

Posted: Thu Mar 25, 2004 7:57 pm
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

Posted: Thu Mar 25, 2004 8:02 pm
by Goowe
:lol:

Posted: Thu Mar 25, 2004 9:08 pm
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

Posted: Fri Mar 26, 2004 2:13 am
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.

Posted: Fri Mar 26, 2004 2:35 am
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...