Click here to Skip to main content
15,886,518 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I succesfuly made the Signup system with the connection to mysql to add new user on the database (username email, name, password hashed) with errors coming with that, but when it comes to the login when I try to submit user information to connect nothing happen and I really don't know why

here is the code :

dbh.inc.php
<?php
  $serverName = '***';
  $dbUsername = '***';
  $dbPassword = '***';
  $dbName = '***'; 
  $dbPort = ***;

 $conn = mysqli_connect($serverName,$dbUsername,$dbPassword,$dbName);
  //$mysqli = new mysqli(****);

  echo $conn->host_info;

  echo ' tentative de connection' ;
	
  if ($conn->connect_error) {
    echo 'Errno: '.$conn->connect_errno;
    echo '<br>';
    echo 'Error: '.$conn->connect_error;
    exit();
  }

functions.inc.php
PHP
function uidExist($conn, $username, $email)
{
 $sql = "SELECT * FROM users WHERE userUid = ? OR usersEmail = ? ;";
 $stmt = mysqli_stmt_init($conn);
 if(!mysqli_stmt_prepare($stmt,$sql)){
   header("location: ../signup.php?error=stmtfailed");
   exit();
 }
 mysqli_stmt_bind_param($stmt,"ss",$username, $email);
 mysqli_stmt_execute($stmt);

 $resultData= mysqli_stmt_get_result($stmt); 

 if($row = mysqli_fetch_assoc($resultData))
 {
  return $row;
 }else{
   $result = false;
   return $result;
 }
 mysqli_stmt_close($stmt);

} 

function emptyImputLogin ($username, $pwd){

  $result = "";
  if(empty($username)||empty($pwd)) {
    $result = true;
  }else {
    $result = false;
  }
  return $result;
  
}

function loginUser($conn,$username,$pwd){
  $uidExist = uidExist($conn, $username, $username);
 

  if ($uidExist === false){
    header("location: ../login.php?error=wronglogin");
    exit();
  }
  $pwdHashed = $uidExist["userPwd"];
  $checkPwd = password_verify($pwd, $pwdHashed);
  if($checkPwd === false){
    header("location : ../login.php?error=wronglogin");
    exit();
  }
  else if ($checkPwd === true){
    session_start();
    $_SESSION["userid"] = $uidExist["usersid"];
    $_SESSION["useruid"] = $uidExist["userUid"];
    header("location : ../index.php");
    exit();
  }
}

login.inc.php
<?php

error_reporting(E_ALL);
ini_set('display_errors', '1');
if (isset($_POST["submit"])){ 

  $username = $_POST["uid"];
  $pwd = $_POST["pwd"];

  require_once 'dbh.inc.php';
  require_once 'functions.inc.php';

  if(emptyImputLogin( $username, $pwd) !== false ){
    header("location: ../login.php?error=emptyinput "); 
    exit();
   }

   loginUser($conn,$username,$pwd);
} 
  else {
  header("location: ../login.php");
  exit();
}

login.php
<?php require 'header.php';?>
<?php require 'includes/dbh.inc.php';?>
<?php require 'includes/functions.inc.php';?>


  <body class="container-fluid" style="background-image: url('empty-photographer-studio-background-abstract-background-texture-of-beauty-dark-and-light-clear-blue-cold-gray-snowy-white-gradient-flat-wall-and-floor.jpg')">
    <h1 class="pullUp m-3 text-center"> The Pull up Theory </h1>

    <!-- Navigation -->


    <section class="signup_form">
      <h2> Log in !</h2>
      <form action="includes/login.inc.php" method="post">
        <div>
          <input type="text" name="uid" placeholder=" Username">
        </div>
        <div>
          <input type="password" name="pwd" placeholder=" Votre mot de passe">
        </div>
        <div>
          <button type="submit" name="submit"> Log In </button>
        </div>
      </form>
      <?php
      if(isset($_GET["error"])){
        if($_GET["error"] == "emptyinput"){
          echo "<p class='text-center text-info'> tous les champs doivent être remplis<p>";
        }
        else if ($_GET["error"] == "wronglogin"){
          echo "<p class='text-center text-info'> mot de passe ou nom utilisateur incorrecte <p>";
        } 
      }
    ?>
    </section>

<?php 
  include_once "footer.php";
?>


header.php

PHP
                <title>Website 
  
  
  
  <h1 class="pullUp m-3 text-center"> The Pull up T</h1>
  
    <div class=" col-4 col-sm-5 col-xs-6 title mt-2"><a class="navbar-brand text-warning" href="#">
      The Pull Up T <svg xmlns="http://www.w3.org/2000/svg" width="30" height="30" fill="currentColor" class="bi bi-lightning-charge-fill text-warning" viewBox="0 0 16 16">
      <path d="M11.251.068a.5.5 0 0 1 .227.58L9.677 6.5H13a.5.5 0 0 1 .364.843l-8 8.5a.5.5 0 0 1-.842-.49L6.323 9.5H3a.5.5 0 0 1-.364-.843l8-8.5a.5.5 0 0 1 .615-.09z">
      </a>
    </div>
    
      
        <span> 
          <svg xmlns="http://www.w3.org/2000/svg" 
="" width="16" height="16" fill="currentColor" class="bi bi-three-dots-vertical text-warning" viewBox="0 0 16 16">
            <path d="M9.5 13a1.5 1.5 0 1 1-3 0 1.5 1.5 0 0 1 3 0zm0-5a1.5 1.5 0 1 1-3 0 
            1.5 1.5 0 0 1 3 0zm0-5a1.5 1.5 0 1 1-3 0 1.5 1.5 0 0 1 3 0z">
          
        </span>
      
      <div class="collapse navbar-collapse" id="navbarSupportedContent">
        <ul class="navbar-nav mr-auto">
          <li class="nav-item active">            <a class="nav-link text-warning" href="index.php">Accueil(current)</a>
          </li>          <li class="nav-item">            <a class="nav-link text-warning" href="Apropos.php">A propos</a>
          </li>                                <a class="nav-link text-warning" href="profile.php"> Profile page</a>
                      ";
              echo "<li class="nav-item">                      <a class="nav-link text-warning" href="logout.php">Log out</a>
                    </li>";
            }else{
              echo "<li class="nav-item">                      <a class="nav-link text-warning" href="signup.php"> Sign up</a>
                     </li> ";
              echo "<li class="nav-item">                      <a class="nav-link text-warning" href="login.php">Log in</a>
                    </li>";
            }
          ?>
          <li class="nav-item">            <a class="nav-link text-warning" href="contact.php">Contacts</a>
          </li>        </ul>
      </div>


What I have tried:

I checked if I put session_start(),added error_reporting(E_ALL);
ini_set('display_errors', '1') to help me see what happen but the error message is :
"Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator at you@example.com to inform them of the time this error occurred, and the actions you performed just before this error.

More information about this error may be available in the server error log."
Posted
Updated 29-Sep-22 5:57am
v4
Comments
Member 15627495 30-Sep-22 11:03am    
$dbport is defined without double quote , look at the db parameters. $dbport = "value";

an internal serv error is 500. no display , because of server run crash.

It's a faulty syntax , quotes missing.
Jordan Nkunga 30-Sep-22 13:46pm    
Thanks for you anwser, I put double quote but still the same errors
Member 15627495 30-Sep-22 16:50pm    
enclose every time you write
<?php .......;;;; ?>

your php require often close tags

    header("location : ../login.php?error=wronglogin",true);    exit(true);



when you use a native php function, check the official website about it.
at www.php.net

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900