php - if else statement problem in phpmysql
Could you help me with my script.
I have made an phpmysql script in which username and email is taken from a form and run it through the database. If the username and email exists in the database it will show 'already exist' other wise it will add to the database.
This is my script.The script is working (not showing any errors) but in the if else statement there is some problem (I think a syntax problem), it only showsalready member exist
even if it is not in database. I am notable to identify the problem. I am a newbe in phpmysql
if(isset($_POST['submit'])) {
$name=mysql_real_escape_string($_GET['name']);
$tes=mysql_real_escape_string($tes);
print $name;
print $tes;
$sel=mysql_query("SELECT * FROM member WHERE email='$tes' AND usrename='$name'");
if(!isset($sel)) {
echo('There is already a member');
}
else
{
//insert
$sql = "INSERT INTO member SET username='$name',email='$tes', date=CURDATE()";
if (@mysql_query($sql)) {
echo('<p>You have been added to database.</p>');
}
}
}
Answer
Solution:
instead of
you can to use
check mysql_num_rows
Answer
Solution:
On your mysql_query line there is a spelling error: AND usrename should be AND username
Answer
Solution:
The following portion of code is not doing what you think it is :
, as long as the query doesn't fail (because of an error in the SQL), will return a resource allowing you to access the resultset.
And even if the query fails, it'll return false -- with means the variable will still be set.
What you probably want is to try fetching some data from the $set resource, to see if your expected (or not) data is there -- see for example .
And if you only want to check if a user exists, no need for a
select *
query -- just use aselect count(*)
, to see how many users correspond to your criteria, without loading their data.Answer
Solution:
you need to add some code..
Answer
Solution:
try this solution
Answer
Solution:
login in core php