Click here to Skip to main content
15,919,178 members
Please Sign up or sign in to vote.
2.50/5 (2 votes)
See more:
hi,
I have a problem here:
first, myquery not executed;
and i catch a errer like this
(Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\Program Files (x86)\EasyPHP-5.3.5.0\www\jadid\logincontrol.php on line 26 )

and in addition, my database is newsdb and tables are users and news and type of username and password are varchar.

Thanks

PHP
$user = $_POST['txtuser'];
$pass = $_POST['txtpassword'];
$con=mysql_connect('localhost','root','');
if(!$con)
{
    echo "Connection is Failed!!";
    exit;
}
mysql_select_db('newsdb');
$query=""select username from users where username='$user' and password='$pass'";
$allRows=mysql_query($query);
if($allRows)
{
    echo "Query Not Executed!!";
    exit;
}
echo $allRows;
$numRows=mysql_num_rows($allRows);
if($numRows)
{
    $_SESSION['user']=$user;
    echo "<center>Welcome ".$_SESSION['user']." to your site<br>";
    echo "<a href=user.php>Please click here on this link to load your page</a></center>";
Posted
Updated 12-Jun-12 5:40am
v7

hi,
you have error in SQL query It self

you did not pass the table name in SLQ query

change query to :
SQL
select username from tablename  where username='@user' and password='@pass
 
Share this answer
 
v2
Thank,
I've found my answer and i explain it:
first,i use:
var_dump($query); 
and second, i use:
or die(mysql_error().": $query"

it's like
$allRows=mysql_query($query)or die(mysql_error().": $query");


now,it's my right code now:

PHP
session_start();
$user = $_POST['txtuser'];
$pass = $_POST['txtpassword'];
$con=mysql_connect('localhost','root','');
if(!$con)
{
    echo "Connection is Failed!!";
    exit;
}
mysql_select_db('newsdb',$con);
$query="SELECT * FROM users WHERE username='$user' AND password='$pass'";
var_dump($query);
$allRows=mysql_query($query)or die(mysql_error().": $query");

if(!$allRows)
{
    echo "Query Not Executed!!";
    exit;
}
echo $allRows;
$numRows=mysql_num_rows($allRows);
if($numRows)
{
    $_SESSION['user']=$user;
    echo "<center>Welcome ".$_SESSION['user']." to your site<br>";
    echo "<a href=user.php>Please click here on this link to load your page</a></center>";
}


Well,i use this codes and i found my problem and then i solved it.
Thanks again.
 
Share this answer
 
v2
Comments
Maciej Los 12-Jun-12 13:26pm    
It's good to find an answer yourself! +5
The mysql_query() function returns FALSE on error. See http://php.net/manual/en/function.mysql-query.php[^]

So,
PHP
if($allRows)
{
    echo "Query Not Executed!!";
    exit;
}


"Query Not Executed!!" will be printed only when the query is actually executed without an error.

Try this to locate the error in your SQL statement:
PHP
$allRows=mysql_query($query) or die('MySQL Error'.mysql_error());
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900