You are viewing our Forum Archives. To view or take place in current topics click here.
what is this error and does it matter
Posted:
what is this error and does it matterPosted:
Status: Offline
Joined: Mar 13, 201311Year Member
Posts: 41
Reputation Power: 1
Status: Offline
Joined: Mar 13, 201311Year Member
Posts: 41
Reputation Power: 1
im getting the error
Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\Social\loginfun.php on line 12
and my code is
Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\Social\loginfun.php on line 12
and my code is
<?php
//session start
session_start();
//intialize connect
mysqli_connect("localhost","root","","social")or mysqli_connect_error();
//define some variables
$username = $_POST['username'];
$password = $_POST['password'];
//check varibles against each other
$sql = mysql_query("SELECT * FROM `users` WHERE `username` = $username && `password` = $password");
//get number of rows and if it = 1
$numrows = mysql_num_rows($sql);
if($numrows = "1"){
//set the session variable
$_SESSION['username'] = $username;
}else{
echo "Wrong username or password";
}
//echo welcome and your logged in as
echo "welcome your logged in as ".$_SESSION['username'];
#2. Posted:
Status: Offline
Joined: Jan 01, 201113Year Member
Posts: 1,957
Reputation Power: 401
Status: Offline
Joined: Jan 01, 201113Year Member
Posts: 1,957
Reputation Power: 401
Your connection is using mysqli, whereas your query is using mysql
Therefore there is no connection on the mysql object.
Change all your mysql statements to the equivalent mysqli statements
Therefore there is no connection on the mysql object.
Change all your mysql statements to the equivalent mysqli statements
- 0useful
- 0not useful
#3. Posted:
Status: Offline
Joined: May 02, 201212Year Member
Posts: 1,129
Reputation Power: 34
Status: Offline
Joined: May 02, 201212Year Member
Posts: 1,129
Reputation Power: 34
You will want to use the same methods.. So do not go from mysqli to mysql. Keep it all the same. Next mysqli required a connection for the first parameter, then the second parameter is whatever the mysql parameter was...
- AND YOUR QUERY IS WRONG!!
Example
So instead of this...
Try this...
- AND YOUR QUERY IS WRONG!!
Example
mysql_query($sql); //Old Version DO NOT USE
mysqli_query($con,$sql) //$con = connection
So instead of this...
$sql = mysql_query("SELECT * FROM `users` WHERE `username` = $username && `password` = $password");
//get number of rows and if it = 1
$numrows = mysql_num_rows($sql);
Try this...
//$con is your connection, So...
$con = mysqli_connect("localhost","root","","social")or mysqli_connect_error();
$sql = mysqli_query($con,"SELECT * FROM users WHERE username = '$username' AND password = '$password'");
//get number of rows and if it = 1
$numrows = mysqli_num_rows($con,$sql);
- 0useful
- 1not useful
You are viewing our Forum Archives. To view or take place in current topics click here.