0

i am trying to get credentials of users via php script, but i forcing with one problem. The source code is

    <?php
    include 'utilities.php'; 
    $conn = openDB();
    $table = "customer"; 
    $username = $_POST['username'];
    $pwd = $_POST['pwd']; 


    $sql = "SELECT * FROM $table WHERE username = '{$username}' and pwd = '{$pwd}' ";
    $result = $conn->query($sql);
    if($result->num_rows > 0)// here is line 12
{

    echo "<br /> Successfully logged in as $username";
    if ($username == "admin")
    echo "<a href='Administrator.html'>Administrator</a>";  
    else
    echo "<a href = 'UserMenu.html'>UserMenu</a>";

}
    else

{

    echo "<br /> Invalid Login";


}
   $conn->close();


   ?>

and the erro is

Connected successfully

Notice: Trying to get property of non-object in

C:\xampp\htdocs\myhost\ProcessLogin.php on line 12

Invalid Login

Jas
  • 5
  • 5
  • but an answer is not working for mine code – Jas Mar 09 '15 at 08:53
  • Please mark line 12 with a comment also did you checked if the connection failed? And which Mysql API do you use? mysqli_* or PDO? – Rizier123 Mar 09 '15 at 08:53
  • connection is successfully, line 12 is – Jas Mar 09 '15 at 08:55
  • if($result->num_rows > 0) – Jas Mar 09 '15 at 08:55
  • This means that your query fails and returns FALSE. What API do you use? Do `var_dump($sql);` before you do your query and check if it is correct – Rizier123 Mar 09 '15 at 08:56
  • please take a look at my edited version question – Jas Mar 09 '15 at 08:56
  • 1. I mean mysql API `mysqli_*` or `PDO` ? 2. what was the output of `var_dump($sql);` ? – Rizier123 Mar 09 '15 at 08:59
  • Connected successfullyobject(mysqli)#1 (19) { ["affected_rows"]=> int(0) ["client_info"]=> string(79) "mysqlnd 5.0.11-dev - 20120503 - $Id: f373ea5dd5538761406a8022a4b8a374418b240e $" ["client_version"]=> int(50011) ["connect_errno"]=> int(0) ["connect_error"]=> NULL ["errno"]=> int(0) ["error"]=> string(0) "" ["error_list"]=> array(0) { } ["field_count"]=> int(0) ["host_info"]=> string(20) "127.0.0.1 via TCP/IP" ["info"]=> NULL ["insert_id"]=> int(0) ["server_info"]=> string(6) "5.6.21" ["server_version"]=> int(50621) ["stat"]=> string(131) "Uptime: 688 Threads: 1 – Jas Mar 09 '15 at 09:02
  • And what is the output of: `var_dump($sql);` ? – Rizier123 Mar 09 '15 at 09:09

0 Answers0