0

When I get into my sign in page it displays the error:

> Fatal error: Uncaught Error: Call to a member function fetch() on bool
> in C:\xampp\htdocs\SUPINFO\Page0\index.php:43 Stack trace: #0 {main}
> thrown in C:\xampp\htdocs\SUPINFO\Page0\index.php on line 43

I don't know why this is happening Here is the code that is causing the error (my index.php page):

<form action="index.php" method="POST">
                <div class="textbox1">
                    <i class="fa fa-user"></i>
                    <input type="text" placeholder="ID" name="ID" value="" required/>
                </div>
                <div class="textbox1">
                    <i class="fa fa-lock"></i>
                    <input type="password" placeholder="Password" name="password" value="" required/>
                </div>
                <div id="submit">
                    <input type="submit"  name ="" value="login">   
                </div>
            </form>

            <?php 
            try
            {
                $bdd = new PDO('mysql:host=localhost;dbname=hps;charset=utf8', 'root', '');
            }
            catch(Exception $e)
            {
                    die('Erreur : '.$e->getMessage());
            }
            ?>
                <?php 
                $id =$_POST['ID'];
                $mdp = $_POST['password'];
                $reponse0 = $bdd->query("SELECT*FROM clients WHERE id_pass='$id'");
                $validation = $reponse0 -> fetch();
                if ($validation['id_pass'] == $id && password_verify($mdp, $validation['password']) )
                    {
                        ?>
                        <script type="text/javascript">
                            window.open("../Page1/index.php");
                        </script>
                <?php 
                    }
                    else{
                        ?>
                        <script type="text/javascript">
                           setTimeout(function(){window.alert("Password or ID is incorrect")},200);
                        </script>
                    <?php
                    }
                ?>
Jason
  • 15,017
  • 23
  • 85
  • 116
  • 1
    Either your query or your connection failed. Also, you need to remove the spaces in `$reponse0 -> fetch()` – Jay Blanchard Mar 23 '20 at 00:50
  • 1
    Hi, this means that `$bdd->query` triggered an error and returned `false`. I also urge you to use [PHP Prepared Statements](https://www.php.net/manual/en/mysqli.quickstart.prepared-statements.php) and to write a more readable code this is painful to watch, other than that good luck khouya =) – Ermac Mar 23 '20 at 00:52
  • Thanks the prepared statements worked for me . – Rajawi Abdo Mar 23 '20 at 15:06

0 Answers0