News:

Bored?  Looking to kill some time?  Want to chat with other SMF users?  Join us in IRC chat or Discord

Main Menu

PHP/MySQL problems..

Started by Tristan Perry, November 03, 2004, 02:36:37 PM

Previous topic - Next topic

Tristan Perry

Hello,
I'm working on a newsletter for my website. I'm trying to check if the e-mail address someone entered into a form is already being used. This is the code I'm using:


// Check to see if e-mail address is already in use
$que = 'SELECT emails FROM emails';
$res = mysql_query($que);
while( $row = mysql_fetch_array($res) )
{
$emails = array(
        'email' => $row['emails']
);
}
foreach( $emails as $email )
{
if( $email['email'] == '[email protected]' )
{
$error2 = "E-mail adddress in use. Subscription not accepted.";
}
}


The email address '[email protected]' is in the database, I can't figure out why the $error2 is never being set..
Any ideas would be greatly appreciated,
Tau Online

Tomer


<?php

// Check to see if e-mail address is already in use
$que 'SELECT emails FROM emails';
$res mysql_query($que)
or die(
"E-mail adddress in use. Subscription not accepted.");
while( 
$row mysql_fetch_array($res) )
{
$emails = array(
        
'email' => $row['emails']
);
}
foreach( 
$emails as $email )
{
if( 
$email['email'] == '[email protected])
{
$error2 "E-mail adddress in use. Subscription not accepted.";
}
}

?>


Oldiesmann

Why can't you just do this?

<?php
$email 
'[email protected]';
$q mysql_query("SELECT emails FROM emails WHERE emails = '$email'");
if(
mysql_num_rows($q) == 1)
{
    
$error2 "E-mail address in use. Subscription not accepted.";
}
?>
Michael Eshom
Christian Metal Fans

Grudge

I'd go with using mysql_num_rows($q) != 0, but otherwise I agree with Olds...
I'm only a half geek really...

[Unknown]

Are you sure you have an emails column on the emails table?  Maybe it's email?

-[Unknown]

Tristan Perry

Thanks all for your help, I've got this working now. It was a problem with another part of the script that was messing this up.. this always happens with me!

Advertisement: