dimanche 21 mars 2021

Logon query error in PHP - Call to undefined function > mysql_fetch_assoc()

I use SQL Server, Xampp and Visual Studio in this project .

I have no problem connecting to the database its work.

But the problem with the login query I'm just starting to use PHP and I need help. Where is the error exactly? And how can I fix it?

This is the form code

   <form action="connect.php" method="post">

                <div class="inputBox">
                    <input type="text" name="user" required="">
                    <label>Username:</label>
                </div>
                <div class="inputBox">
                    <input type="password" name="pass" required="">
                    <label>Password:</label>
                </div>
                <center>
                    <input type="submit" name="" value="login">
                </center>
            </form>

and this is php code

    <?php
//Connection space:
$serverName = "DESKTOP-UJE8RHN\SQLEXPRESS";

$connectionInfo = array("Database"=>"7thOfficeDB");

$conn = sqlsrv_connect( $serverName , $connectionInfo);

if( $conn ){
    echo "Connection establisdhed.<br/>";
} else { 
echo "Connection could not be establisdhed.<br/>";
  die (print_r (sqlsrv_errors(), true)); }

  //end

  //login : 

if (empty($_POST['user']) || empty($_POST['pass'])) {
 echo " user or pass is empty ! ";
} else { 

$sql=("SELECT * FROM `emp` where `user_emp`=".$_POST['user']."AND `pass_emp`=".$_POST['pass']);
//line 25 -->
$result = mysql_fetch_assoc($sql);
if ($result == 0)
{ echo " Password or username is wrong"; } 
else 
{  header("Location: EmpPage.html");   } 
  }
?>

and I get this error after I try to login.

Connection establisdhed.

Fatal error: Uncaught Error: Call to undefined function mysql_fetch_assoc() in C:\xampp\htdocs\website\connect.php:25 Stack trace: #0 {main} thrown in C:\xampp\htdocs\website\connect.php on line 25

Please help me.




Aucun commentaire:

Enregistrer un commentaire