title: Why doesn't my prepare statement work?
body: <p>For some reason, my prepare statement doesn't seem to return any rows or login, although I'm sure the password and username being entered is correct; when running the code without the prepare statement, the system logs in. Would anyone happen to know why my prepare statement isn't working, or if there is some other method I should use?</p>
  
  <pre><code>&lt;?php session_start(); ?&gt;
  &lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;head&gt;
      &lt;title&gt;Logged in&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
      &lt;?php
  
          $user=$_GET["username"];
          $pass=$_GET["password"];
  
  
          $servername="localhost";
          $username="root";
          $password="";
          $dbName="db_artzytest";
  
          $conn=new mysqli($servername, $username, $password, $dbName);
  
          if($conn-&gt;connect_error){
              echo $conn-&gt;connect_error;
              die("connection to server not found");
          }else{
              echo "connection established";
          }
          ///finds account with matching login info
          $sql="SELECT * FROM db_users WHERE username='{$user}' AND password='{$pass}' ";
  
  
          $sql="SELECT * FROM db_users WHERE username = ? AND password = ?";
  
  
          try{
              $stmt = $conn-&gt;prepare($sql);
              $stmt-&gt;bind_param("ss", $user, $pass);
              $stmt-&gt;execute();
        }catch(Exception $e){
            die("prepare failed: " . $e);
        }
          echo 'here';
          //$result = $stmt-&gt;store_result();
  
          printf("Number of rows: %d. \n", $stmt-&gt;num_rows);
  
          //$result=$conn-&gt;query($sql);   
          echo 'here';
          if( mysqli_num_rows($result) &gt; 0 ){
  
              while($row=mysqli_fetch_assoc($result)){
                  //only logs in if the account is activated
                  if($row["isActivated"]==1){
  
                      $_SESSION["currentUser"]=$user;
                      $_SESSION["currentId"]=$row["id"];
                      $_SESSION["currentPass"]=$pass;
  
                      //header( 'Location: ../ProfilePage/profilePage.php' );
                      header( 'Location: ../Content/displayGroup.php?group=general' );
                  }else{
                      $_SESSION["m_Login"]="Unverified Account. Check your email to verify.";
                      header('Location: Login.php');
                  }
              }
              /*
              $sql=" SELECT * FROM table_images WHERE userid = {$_SESSION["currentId"]} ";
  
              $result=$conn-&gt;query($sql);
  
              if(mysqli_num_rows($result) &gt; 0){
                  while($row=mysqli_fetch_assoc($result)){
                      echo "&lt;img style='height: 10vh; width: 10vw;' src='../../images/{$row["id"]}.jpg' /&gt;";
                      echo "{$row["imageName"]}&lt;/br&gt;";
                  }
              }
              */
  
          }else{
              $_SESSION["m_Login"]="password or username incorrect {$user} {$pass}"  . var_dump(mysqli_stmt_get_result($stmt) );
              header('Location: Login.php');
              echo "no user found";
          }
  
      ?&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>