Call to a member function bindParam() on string

Asked 2 years ago, Updated 2 years ago, 50 views

The cause of this error is unknown.
I am sorry to trouble you, but I would appreciate it if you could let me know.
Thank you for your cooperation.

Fatal error:Uncaught Error:Call to a member function bindParam() on string in/home/users/2/lolipop.jp-7084e0fe7e215321/web/study/mysql/login.php:21 Stack trace:#0 {main}thrown in/home/users/70327 lolipop.jp
<?php
ini_set('display_errors',1);

require'./library.php';
$err=[];
$email=';
$pass=';
$stmt=';
if($_SERVER['REQUEST_METHOD'] === 'POST') {
    $email=filter_input(INPUT_POST, 'email', FILTER_SANITIZE_EMAIL);
    $pass=filter_input(INPUT_POST, 'pass', FILTER_SANITIZE_STRING);
    if($email==='||$pass==='){
        $err['login'] = 'blank';
    } else{
        $db = connect();
        $stmt=$db->prepare('select id, name, pass from members where email=:email limit1');
        if(!$stmt){
            die($db->error);
        }
    }
    $stmt->bindParam(':email', $email,PDO::PARAM_STR);
    $success=$stmt->execute();
    if(!$success){
        die($db->error);
    }
    $hash = $stmt->fetchColumn(2);
    $stmt->fetch();
    if(password_verify($pass,$hash)){
    } else{
        $err['login'] = 'failed';
    }
} ?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" >
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
  <link rel="stylesheet" type="text/css" href="style.css"/>
  <title>Log in </title>
</head>

<body>
  <divid="wrap">
    <divid="head">
      <h1>Log in </h1>
    </div>
    <divid="content">
      <divid="lead">
        <p> Log in with your email address and password.</p>
        <p>If you haven't completed the membership process yet, please click here.</p>
        <p>&raquo;<a href="join/">Apply for membership<a></p>
      </div>
      <form action="method="post">
        <dl>
          <dt>mail address</dt>
          <dd>
            <input type="text" name="email" size="35" maxlength="255" value="<?phpechoh($email);?>"/>
            <?php if(isset($err['login'])&$err['login']==='blank'):?>
              <p class="error"> Enter your email address and password</p>
            <?php endif;?>
            <?php if(isset($err['login'])&$err['login']==='failed'):?>
              <p class="error">Login failed</p>
            <?php endif;?>
          </dd>
          <dt>Password</dt>
          <dd>
            <input type="password" name="password" size="35" maxlength="255" value="<?phpechoh($pass);?>"/>
            <?php if ($err['login'] === 'blank'): ?>
              <p class="error">Please enter your password</p>
            <?php endif;?>
          </dd>
          <dt>Login </dt>
          <dd>
            <input id="save" type="checkbox" name="save" value="on">
            <label for="save">Log in automatically from next time</label>
          </dd>
        </dl>
        <div>
          <input type="submit" value="Log in"/>
        </div>
      </form>
    </div>
    <divid="foot">
      <p><img src="images/txt_copyright.png" width="136" height="15" alt="(C)H2O Space.MYCOM"/>/p>
    </div>
  </div>
</body>
</html>

php mysql

2022-09-30 16:59

1 Answers

The error message indicates that $stmt is a string, but you are trying to call bindParam().
In other words,

$stmt=';
if($_SERVER['REQUEST_METHOD'] === 'POST') {
$email=filter_input(INPUT_POST, 'email', FILTER_SANITIZE_EMAIL);
$pass=filter_input(INPUT_POST, 'pass', FILTER_SANITIZE_STRING);
if($email==='||$pass==='){
    $err['login'] = 'blank';
} else{
    $db = connect();
    $stmt=$db->prepare('select id, name, pass from members where email=:email limit1');
    if(!$stmt){
        die($db->error);
    }
}
$stmt->bindParam(':email', $email,PDO::PARAM_STR);

You are trying to call bindParam() to $stmt that is initialized with $stmt=';.
This is probably because $email is empty or $pass is empty, so if statements are missing without a database connection.Make sure that $email and $pass contain values.


2022-09-30 16:59

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.