doudongdang4483 2016-10-28 05:17
浏览 24

stmt绑定结果总是返回0

I have a problem with my login script, everything woks 100% no errors, but the stmt bind result is always returning 0 and in the database it is 1. so on the dashboard i cant load the users data, because i get the users information based on the session var. Here is the processing script.

<?php
if (isset($_POST['btn_login'])) {
  if ($_POST['login_username'] == '') {
    $_SESSION['login_error'] = 'Please fill in the username field.';
    redirect('login/?error'); // these are custom functions created on a separate file
  }
  if ($_POST['login_password'] == '') {
    $_SESSION['login_error'] = 'Please fill in the password field.';
    redirect('login/?error'); // these are custom functions created on a separate file
  }
  $username = (string) $_POST['login_username'];
  $password = (string) hash('sha512', $_POST['login_password']);
  $stmt = $mysqli->prepare("SELECT user_id FROM users WHERE username = ? AND password = ?");
  $stmt->bind_param("ss", $username, $password);
  $stmt->execute();
  $stmt->store_result();
  if ($stmt->num_rows == 1) {
    $stmt->bind_result($id);
    $_SESSION['id'] = (int) $id;
    $_SESSION['login_fingerprint'] = fingerprint(); // fingerprint is a custom function created on a separate file
    $stmt->close();
    session_regenerate(); // these are custom functions created on a separate file
    redirect('dashboard'); // these are custom functions created on a separate file
  } else {
    $stmt->close();
    $_SESSION['login_error'] = 'Wrong username/password entered, please check to see if you entered them correctly.';
    redirect('login/?error');
  }
}
?>

here is the database structure. It is a simple database structure.

CREATE TABLE `users` (
  `user_id` int(11) NOT NULL,
  `username` varchar(250) COLLATE utf8_unicode_ci NOT NULL,
  `password` varchar(250) COLLATE utf8_unicode_ci NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

My goal is to get it to return the user_id and set it to the session var.

Here is a link to the full script

https://github.com/WhiteNicholas/php_login_system

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 2020长安杯与连接网探
    • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
    • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
    • ¥16 mybatis的代理对象无法通过@Autowired装填
    • ¥15 可见光定位matlab仿真
    • ¥15 arduino 四自由度机械臂
    • ¥15 wordpress 产品图片 GIF 没法显示
    • ¥15 求三国群英传pl国战时间的修改方法
    • ¥15 matlab代码代写,需写出详细代码,代价私
    • ¥15 ROS系统搭建请教(跨境电商用途)