Page 1 of 1

Problem using two paramenters in preprare statement to login

Posted: Tue May 17, 2016 10:18 am
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

Re: Problem using two paramenters in preprare statement to l

Posted: Tue May 17, 2016 10:29 am
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.

Re: Problem using two paramenters in preprare statement to l

Posted: Tue May 17, 2016 11:12 am
by adsegzy
Thanks Celauran

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

Thanks greatly.