473,387 Members | 1,483 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

IF statement with SQL query

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
2 3415
ljayz
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
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

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

Similar topics

7
by: Bob | last post by:
Currently I am using this statement to translate 3 fields in my db thru Visual Basic. I import the data from one table to another then call the IFF statements and the NewDate to translate the...
7
by: mark | last post by:
Access 2000: I creating a report that has a record source built by the user who selects the WHERE values. An example is: SELECT * FROM CHARGELOG WHERE STDATE Between #10/27/2003# And...
4
by: Polly | last post by:
I had a macro that ran a parameter query and created and opened an Excel file with the system date as part of the file name, but I had to change the file name by hand. So I converted the macro to...
3
by: Andy_Khosravi | last post by:
I have been trying to build a user friendly search engine for a small database I have created. I'm having some particular problems with one of my date fields. Here's the setup: I'm using...
14
by: Siv | last post by:
Hi, I just discovered that if in an ADO.NET query I use: "Select * from Invoices Where InvoiceDate BETWEEN StartDate AND EndDate;" In this case StartDate would be 1st of month and EndDate...
2
by: Geoffrey KRETZ | last post by:
Hello, I'm wondering if the following behaviour is the correct one for PostGreSQL (7.4 on UNIX). I've a table temp_tab with 5 fields (f1,f2,f3,...),and I'm a launching the following request :...
1
by: Matt | last post by:
I am writing a DELETE statement and I want to filter the records using another SELECT statement. My SELECT statement is a GROUP BY query that grabs all social security numbers from the "Data...
0
ADezii
by: ADezii | last post by:
One frequently asked question at TheScripts is "Should I use a Stored Query or an SQL Statement in those situations that require a Query (RecordSets, RecordSources, Append, Delete, Update Operations,...
3
by: Joshepmichel | last post by:
Please to help me to following problem I want to do this 1. create Table Name MEMBER on the Database Name "mytestdb", 2. Add the Values to the Table through the Key board Inputs during running...
3
by: Eric Davidson | last post by:
DB2 9.5 I keep geting the message. SQL0101N The statement is too long or too complex. SQLSTATE=54001 When one of my sql statements takes over 60 seconds to compile the sql statement. Is...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.