0

hello my dear Friends,
for a long time i was not here. I hope u all are geting well. again i have problem in login form anyone can guide me plz, code is below

<?php
   include "conn.php";

  if($_SERVER["REQUEST_METHOD"] == "POST"){ 
$username = filter_input(INPUT_POST, 'username', FILTER_SANITIZE_SPECIAL_CHARS);
$password = filter_input(INPUT_POST, 'password', FILTER_SANITIZE_SPECIAL_CHARS);

$sql = "SELECT * FROM admintb WHERE username = '$username' and passcode = '$password'";

$result = $conn->query($sql);

if( $result->num_rows > 0)
 {

         echo "welcome!! You are loged in ";
      }else {
         $error = "Your Login Name or Password is invalid";
      }
  }
?>

Pleaez hepl me as soon as posible.

Edited by zebnoon1

4
Contributors
8
Replies
35
Views
1 Year
Discussion Span
Last Post by zebnoon1
0

yes , with below code i always receive error " Trying to get property of non-object in "

<?php
   include "conn.php";

 if ($_SERVER["REQUEST_METHOD"] == "POST"){ 
$username = filter_input(INPUT_POST, 'username', FILTER_SANITIZE_SPECIAL_CHARS);
$password = filter_input(INPUT_POST, 'password', FILTER_SANITIZE_SPECIAL_CHARS);

$sql = "SELECT * FROM admintb WHERE username = '$username' and passcode = '$password'";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
     // output data of each row
     while($row = $result->fetch_assoc()) {
         echo "<br> id: ". $row["id"]. " - Name: ". $row["AdminName"]. " " . $row["Position"] . "<br>";
     }
} else {
     echo "0 results";
}
  }
$conn->close();
?>

Edited by zebnoon1

0

with below code i always receive error " Trying to get property of non-object in "

What line exactly?

0

From: http://php.net/manual/en/mysqli.query.php

Returns FALSE on failure. For successful SELECT, SHOW, DESCRIBE or EXPLAIN queries mysqli_query() will return a mysqli_result object. For other successful queries mysqli_query() will return TRUE.

Seems you are getting FALSE as $result is not an object.

You can always check the last error :

if(!$result) printf("Errormessage: %s\n", $conn->error);

Edited by diafol

0

then what can i use instead of

$result->num_rows > 0

Please guide me in detail ....

1

You must first ascertain whether you have a successful query or not. If so, use your code, if not, check what the problem is (my one-liner).

0

ok thx i soved this problem, some mistype was there .....i post correct code here.

<?php
   include "conn.php";

 if ($_SERVER["REQUEST_METHOD"] == "POST"){ 
$username = filter_input(INPUT_POST, 'user', FILTER_SANITIZE_SPECIAL_CHARS);
$password = filter_input(INPUT_POST, 'pass', FILTER_SANITIZE_SPECIAL_CHARS);

$sql = "SELECT * FROM admintb WHERE username ='$username' and password='$password'";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
     // output data of each row
     while($row = $result->fetch_assoc()) {
         echo "<br> id: ". $row["id"]. " - Name: ". $row["NameAdmin"]. " " . $row["Position"] . "<br>";
     }
} else {
     echo "0 results";
}
  }
$conn->close();
?>  
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.