/    Sign up×
Community /Pin to ProfileBookmark

Help with User Logins

I’m looking at various resources in order to understand how to create user logins for a website, but every time I try something goes wrong. Specifically…well below is my code, where specifically this line “$numrows = mysql_num_rows($query);” gives me the error “Warning: mysqli_stmt_num_rows() expects parameter 1 to be mysqli_stmt, string given” and I have no clue how to fix this. If someone could help it’d be greatly appreciated. Connection to the database works fine, it’s that one line though that gives me grief.

[CODE]
$myusername = $_POST[‘username’];
$mypassword = $_POST[‘pass’];

if ($myusername && $mypassword) {
$connection = @new mysqli($host, $username, $password, $db_name);
if ($connection->connect_error) {
die(‘Connect Error’ . $connection->connect_error);
} else {
echo ‘Successfully Connected to the Database’;

$query = “SELECT * FROM logins WHERE username = ‘$username'”;

$numrows = mysql_num_rows($query);

if ($numrows !=0) {
while($rows = mysql_fetch_assoc($query)) {
$db_username = $row[‘username’];
$db_password = $row[‘password’];
}

if ($myusername == $db_username && $mypassword == $db_password) {
echo “Login Successful”;
} else {
echo “The username and/or password were incorrect”;
}

}
}
}

[/CODE]

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@jimr451Jul 18.2012 — You forgot to run:

[code=php]$result = mysql_query($query);[/code]

then call [B]mysql_num_rows[/B] on [B]$result[/B].

-Jim
×

Success!

Help @JustWhatever spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...