By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,664 Members | 1,669 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,664 IT Pros & Developers. It's quick & easy.

IF statement with SQL query

P: 2
Am really beginner at this so sorry in advance.

i have a database that i can connect to and insert data etc.
it is an email database in which i want users to be able to add their email address. At the moment, all works well with the adding of emails.
my problem is that if you put the users email adddress in the form again, the email address gets added again into the database.

the script that i found does not work...
i have worked for days just trying to get the IF statement to work correctly but cannot work out the variables?

here it is.

require('connect.php');
$form_email = ($_POST['email']);
function emailChecker($email){
global $check_result;
$check = "SELECT id FROM esubs WHERE email = '$form_email'";
$check_result = mysql_query($check) or die(mysql_error());
if(!mysql_num_rows($check_result)) return false;
else return true;
mysql_close();
}


i simplified it so that if the query found something, then it printed a"found result" or if nothing was found then print "nothing Found"

this is the script i did up.

require('connect.php'); // Connect to the database
$form_email = ($_POST['email']);
$SQL= "SELECT * FROM esubs WHERE email = '$form_email'";
$check_result = mysql_query($SQL);
if(mysql_query($SQL)) {
print 'found result';
} else {
print 'Nothing found';
}



but no matter what email i put into the field, i get found result.
if i put a ! in front of the mysql_query($SQL)) {
making it:
if(!mysql_query($SQL)) {

then every time i get nothing found....

Please help....
thats if this makes sense....
Apr 30 '07 #1
Share this Question
Share on Google+
2 Replies


P: 5
require('connect.php'); // Connect to the database
$form_email = ($_POST['email']);
$SQL= "SELECT * FROM esubs WHERE email = '$form_email'";
$check_result = mysql_query($SQL);
if(mysql_query($SQL)) {
print 'found result';
} else {
print 'Nothing found';
}

try this

if(mysql_fetch_array($check_result)){
print 'found result';
} else {
print 'Nothing found';
}

i guess you miss one code mysql_fetch_array
Apr 30 '07 #2

P: 2
try this

if(mysql_fetch_array($check_result)){
print 'found result';
} else {
print 'Nothing found';
}

i guess you miss one code mysql_fetch_array

AWESOME..... thankyou so much!!!!!!

it pays to ask for help it seems.... could have saved me hours....
Very much appeciated!!!!!
Apr 30 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.