Problem using two paramenters in preprare statement to login

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
adsegzy
Forum Contributor
Posts: 184
Joined: Tue Jul 28, 2009 9:26 am

Problem using two paramenters in preprare statement to login

Post by adsegzy »

Hello,
I have a login page and I am trying to use the input username & password to confirm member. Below is my code but it is not echoing the name out.

Code: Select all

$uname = $_POST[username];			
$pword = $_POST[password]:

$get = $dWay->prepare(SELECT firstname, lastname, city FROM members WHERE username=? AND password=?);
$get->bind_param('s, s', $uname, $pword);
$get->execute();
$get->bind_result($fname, $lname, $city);
$get->fetch();
echo $fname;
If I use one parameter like in below code, It will echo out the name. But I must use two (username & password) parameter

Code: Select all

$get = $dWay->prepare(SELECT firstname, lastname, city FROM members WHERE username=?);
$get->bind_param('s', $uname);

//OR

$get = $dWay->prepare(SELECT firstname, lastname, city FROM members WHERE password=?);
$get->bind_param('s', $pword);
Please what could be the problem, because I must use both Email & Password to confirm each member.

Thanks
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Problem using two paramenters in preprare statement to l

Post by Celauran »

Get rid of the comma.

Code: Select all

$get = $dWay->prepare("SELECT firstname, lastname, city FROM members WHERE username=? AND password=?");
$get->bind_param('ss', $uname, $pword);
$get->execute();
$get->bind_result($fname, $lname, $city);
$get->fetch();
echo $fname;
You could get rid of $uname and $pword, too, as they serve very little purpose, but that's another story.
adsegzy
Forum Contributor
Posts: 184
Joined: Tue Jul 28, 2009 9:26 am

Re: Problem using two paramenters in preprare statement to l

Post by adsegzy »

Thanks Celauran

It works, like magic. I have been on this for more than an hour.

Thanks greatly.
Post Reply