PHP/MySQL SELECT statement with 'variable' ' ' or 'variable' IS NOT NULL
not working
I have a SQL routine written that compares a user's input with an existing
value in a table. If the value exists, a green check mark appears next to
the input. If it doesn't, then a red x appears. My SQL statement is as
follows:
$check = $con->prepare("SELECT count(*) FROM emaillist");
$check->execute();
$result = $check->fetchColumn(); //Get no. of columns
$check = $con->prepare("SELECT Username FROM emaillist WHERE Username =
'$Name' AND '$Name' <> '' ");
$check->execute();
$result = $check->fetchColumn(); //Get exact column
if(!$result) {
show red x } else { show green check }
This works fine as long as there is input. The red x appears when the
input doesn't match and the green check appears when it does; however, I
don't want anything to display if the field is left blank. Right now, the
red x appears if the field is empty or is null. Using IS NOT NULL didn't
work, either. What am I missing?
No comments:
Post a Comment