php读取mysql当前会员名称,MySQL php使用另一列获取列(使用用户名获取密码)

After successfully verifying username exists in the database, I need to verify whether the password matches as well. Therefore, I need to retrieve the hashed password from the database, right? Or do I have other choices?

I'm using PHP 5.5 API bcrypt for hashing. My code would give me a 500 internal server error when I get the password from database. How do I do this correctly?

Here's my php code:

// If found username, check password, else respond invalid username

if($countRows!==0){

// Get hash from database

// Prepare statement

$stmt = $conn->prepare('SELECT password FROM users WHERE username = ?');

// Bind

$stmt->bind_param('s', $ps_username);

// Set Parameters

$ps_username = $username;

// Execute

$hash = $stmt->execute();

// Check password

if (!password_verify($password, $hash)) {

if($error != ""){

$error .= '
';

}

$error .= 'The user or password you entered do not match, please try again.';

}

else {

echo 'OK';

// Session start

// Redirect user to profile/homepage

}

}

And can someone recommend something that I can learn SQL commands? I can't find a good place for that.

解决方案

execute() does not return any column data. It returns a boolean (true/false). This is where your code block first fails:

$hash = $stmt->execute();

You can view examples on how to fetch data from the result set here: http://php.net/manual/en/mysqli-stmt.fetch.php

An example being:

$stmt->execute();

$stmt->bind_result($hash);

$stmt->fetch();

In response to:

And can someone recommend something that I can learn SQL commands?

This is pretty much off topic for Stackoverflow but the PHP manual for mysqli can show you how to use the mysqli API fairly well with plenty of examples. If you want to learn the Structured Query Language itself, then there are plenty of external resources for that, including MySQL's documentation.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值