-4

I made this script yesterday at my home and it worked fine. And now its not working here in my job.

i'm getting this erro...

Notice: Undefined variable: conn in C:\xampp\htdocs\cef\login_sys.php on line 10

Fatal error: Call to a member function query() on a non-object in C:\xampp\htdocs\cef\login_sys.php on line 10.

here is the script for login_sys.php

<?php

include 'includes/dbh.php';

$email= $_POST['email'];
$password= $_POST['password'];


$sql =("SELECT * FROM usuarios WHERE email='$email' AND    
 password='$password'");                          
 $result = $conn->query($sql);
 if(!$row = $result->fetch_assoc()) {
 echo "Your information is invalid!! <br>
 or user is not in our server = (
";

  }else{

$_SESSION['id']= $row['id'];
if (isset($_SESSION['id'])){
      echo $_SESSION['id'];

      }else{
          echo "Your not logged in";

          }

 //header("Location: central.php");

 }
 ?>

here is the inclued folder with my conn variable the includes/dbh.php...

 //$servername = "***";
 //$username = "***";
 //$password = "****";
 //$dbname = "***";

 //create the connection
 $conn = mysqli_connect ('***', '**', '***', '***');
 if(!$conn) {
 die("Connection faild: ".mysqli_connect_error());  
 }

 ?>

Whats wrong?

Thamilhan
  • 13,040
  • 5
  • 37
  • 59
James Allan
  • 5
  • 1
  • 5
  • you sure copied all the same files and the same db connection file? check your path also and make sure you started the session. use http://php.net/manual/en/function.error-reporting.php – Funk Forty Niner Jun 02 '16 at 12:34
  • Ok James.... you have answers below but that isn't the problem here. If you took off somewhere, for something your boss needs you to do (or whatever other reason), then I probably won't be here by the time you get back. Again, look at my first comment. Edit: Oh, I see you're only responding to answers. Ok, I'm done here, good luck. – Funk Forty Niner Jun 02 '16 at 12:44
  • other thing is that i have the same files in difrent folders and there are the same.in my folder .../cef. i was trying to use the login_sys from that folder. but then i change my link to C:\xampp\htdocs\mytest\login_sys.php... and worked fine...but the weird thing is why it didnt work, if all the files are the same? Everythinh i working now btw lol – James Allan Jun 02 '16 at 13:05

1 Answers1

1

You are tryng to invoke the query method of the class mysqli on a descriptor. Use

$conn=new mysqli('','','','');

instead of

$conn=mysqli_connect();
Riccardo Bonafede
  • 610
  • 1
  • 9
  • 17