Closed Thread
Thread Tools Search this Thread
Unread 18th Oct 2013, 09:44 PM   #1
Active Warrior
 
Join Date: 2010
Location: Malaysia
Posts: 36
Thanks: 14
Thanked 0 Times in 0 Posts
Default
PHP LOGIN SCRIPT
Share on: 
fb share twitter share gplus share more share

i am trying to create a php login script but i am having this error

Warning: mysql_num_rows() expects parameter 1 to be resource, object given in C:\wamp\www\examSystem\login.php on line 57


THIS IS MY CODE

<?php

$sql = "SELECT * FROM studentlogin WHERE user_name = '$loginName' AND password = '$password'";
$result = mysqli_query($con,$sql) or die(mysqli_error("Error:"));
$count = mysql_num_rows( $result);
//if(mysql_num_rows(resource $result) == 1)

print("$count");

if( $count == 1)
{
header('Location: http:lecturer.html');
}
else
{
echo "Wrong Username or Password";
}
mysqli_close($con);
?>
lloydblinks is offline  
Unread 19th Oct 2013, 11:29 AM   #2
Active Warrior
War Room Member
 
Join Date: 2012
Posts: 46
Thanks: 9
Thanked 17 Times in 15 Posts
Default
Re: PHP LOGIN SCRIPT
Share on: 
fb share twitter share gplus share more share

I'm suspecting there's something wrong with your sql query could you test running it in phpmyadmin(if you have access to it) and see if the query is actually obtaining any info from the database.

Code:
And if you wrap your code in [ CODE] tags it's much easier to read.
Delta90 is offline  
The Following User Says Thank You to Delta90 For This Useful Post:
Unread 20th Oct 2013, 06:43 AM   #3
Wordpress Mover on Fiverr
 
Join Date: 2013
Posts: 39
Thanks: 1
Thanked 4 Times in 4 Posts
Default
Re: PHP LOGIN SCRIPT
Share on: 
fb share twitter share gplus share more share

Here it's your answer: http://www.facestatistic.com/test.php I have created this specially for you. All you will have to do is to modify the script where needed and add the AND condition on the query.
Tell me if it is working.

Regards.

wordpressguru is offline  
The Following User Says Thank You to wordpressguru For This Useful Post:
Unread 20th Oct 2013, 04:11 PM   #4
Wordpress Mover on Fiverr
 
Join Date: 2013
Posts: 39
Thanks: 1
Thanked 4 Times in 4 Posts
Default
Re: PHP LOGIN SCRIPT
Share on: 
fb share twitter share gplus share more share

Originally Posted by vmb2013 View Post

I'm also getting a similar error when i try to add adsense to my php site.
What kind of error? Could you post your script and error here? Or, could you post a link to see this error?

wordpressguru is offline  
Unread 21st Oct 2013, 10:52 AM   #5
Active Warrior
 
Join Date: 2010
Location: Malaysia
Posts: 36
Thanks: 14
Thanked 0 Times in 0 Posts
Default
Re: PHP LOGIN SCRIPT
Share on: 
fb share twitter share gplus share more share

thanks to every one the prolem was, i was making use of == instead of === and i was also mixing mysli_num_rows and mysl_num_rows.

this is my new code and it is working perfectly.

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>

//code



<?php

$users = $_POST["users"];

$loginName = $_POST["loginName"];
$password = $_POST["password"];


$loginName = stripslashes($loginName);
$password = stripslashes($password);

$loginName = mysql_real_escape_string($loginName);
$password = mysql_real_escape_string($password);


$con = mysqli_connect("localhost","root","","online_exam" );
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();

}

if($users == "Administrator")
{


$sql = "SELECT * FROM adminlogin WHERE user_name = '".$loginName."' AND password = '".$password."'";


$result = mysqli_query($con,$sql) or die(mysqli_error($con));
$row = mysqli_fetch_array($result);

if($row['user_name'] === $loginName && $row['password'] === $password )
{
//echo $row['user_name'];


header('Location:Admin.html');
}
else
{
echo "wrong password";
}
}

else if($users == "Lecturer")
{

//$sql = "SELECT * FROM studentlogin WHERE user_name = '$loginName' AND password = '$password'";

$sql = "SELECT * FROM adminlogin WHERE user_name = '".$loginName."' AND password = '".$password."'";
$result = mysqli_query($con,$sql) or die(mysqli_error($con));



$row = mysqli_fetch_array($result);

if($row['user_name'] === $loginName && $row['password'] === $password )
{
//echo $row['user_name'];
header('Location:lecturer.html');

}
else
{
echo "wrong password";
}

}
else if($users == "Student")
{
$sql = "SELECT * FROM studentlogin WHERE user_name = '".$loginName."' AND password = '".$password."'";
$result = mysqli_query($con,$sql) or die(mysqli_error($con));


$row = mysqli_fetch_array($result);

if($row['user_name'] === $loginName && $row['password'] === $password )
{
header('Location:student.html');
}
else
{
echo "wrong password";
}
}
mysqli_close($con);
?>
lloydblinks is offline  
Unread 21st Oct 2013, 10:53 AM   #6
Active Warrior
 
Join Date: 2010
Location: Malaysia
Posts: 36
Thanks: 14
Thanked 0 Times in 0 Posts
Default
Re: PHP LOGIN SCRIPT
Share on: 
fb share twitter share gplus share more share

this is my new code and it is working perfectly now.

<?php

$users = $_POST["users"];

$loginName = $_POST["loginName"];
$password = $_POST["password"];


$loginName = stripslashes($loginName);
$password = stripslashes($password);

$loginName = mysql_real_escape_string($loginName);
$password = mysql_real_escape_string($password);


$con = mysqli_connect("localhost","root","","online_exam" );
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();

}

if($users == "Administrator")
{


$sql = "SELECT * FROM adminlogin WHERE user_name = '".$loginName."' AND password = '".$password."'";


$result = mysqli_query($con,$sql) or die(mysqli_error($con));
$row = mysqli_fetch_array($result);

if($row['user_name'] === $loginName && $row['password'] === $password )
{
//echo $row['user_name'];


header('Location:Admin.html');
}
else
{
echo "wrong password";
}
}

else if($users == "Lecturer")
{

//$sql = "SELECT * FROM studentlogin WHERE user_name = '$loginName' AND password = '$password'";

$sql = "SELECT * FROM adminlogin WHERE user_name = '".$loginName."' AND password = '".$password."'";
$result = mysqli_query($con,$sql) or die(mysqli_error($con));



$row = mysqli_fetch_array($result);

if($row['user_name'] === $loginName && $row['password'] === $password )
{
//echo $row['user_name'];
header('Location:lecturer.html');

}
else
{
echo "wrong password";
}

}
else if($users == "Student")
{
$sql = "SELECT * FROM studentlogin WHERE user_name = '".$loginName."' AND password = '".$password."'";
$result = mysqli_query($con,$sql) or die(mysqli_error($con));


$row = mysqli_fetch_array($result);

if($row['user_name'] === $loginName && $row['password'] === $password )
{
header('Location:student.html');
}
else
{
echo "wrong password";
}
}
mysqli_close($con);
?>
lloydblinks is offline  
Closed Thread


Bookmarks

Tags
login, php, script

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




All times are GMT -6. The time now is 09:15 AM.