PHP代码在服务器中出错,但在本地运行良好

时间:2018-11-25 08:56:55

标签: php forms session mysqli server

我的网站在本地运行良好,但是当我上传它时,php代码出现了一些错误,

警告:mysqli :: prepare():无法在第15行的/home/gh/public_html/abida/C/login.php中获取mysqli

致命错误:在第16行的/home/gh/public_html/abida/C/login.php中的null上调用成员函数bind_param()

        <?php
    require '../api/dbcon.php';
    require '../api/apiOnly.php';
          if(session_id() == '' || !isset($_SESSION)) {
        // session isn't started
                 session_start();
              }  
    //FACULTY - USER LOGIN
    if(isset($_POST['login'])){
      //do query here
      $stmt = $conn->prepare('SELECT username, campus, designation FROM accounts where username = ? AND password = ? ');
      $stmt->bind_param('ss', $u, $p);
      $u=$_POST['username'];
      $p=md5($_POST['password']);
      $stmt->execute();
      $stmt->bind_result($username,$campus, $designation);
      if($stmt->fetch()>0){
       $_SESSION['usr_fullname'] = $username;
       $_SESSION['usr_type'] = $designation;
      $_SESSION['usr_campus'] = $campus;
       if($_SESSION['usr_type']=='admin'){
    header('location: home.php');
       exit();
       }else if($_SESSION['usr_type']=='director'){
       header('location: director-index.php');
       exit(); 
       }
      }else{
     $faculty = json_decode($api->authenticate_student($_POST['username'],$_POST['password']),true);
       if(!empty($faculty[0]['usr_fullname'])){
       $_SESSION['usr_fullname'] = $faculty[0]['usr_fullname'];
        $_SESSION['usr_type'] = 'faculty';
        header('location: faculty-index.php');
       }else{
            echo "<script type='text/javascript'>
                    alert ('Username and Password unmatched!'); 
                    window.location.href='login.php';</script>";
    } 
      }
      $stmt->close();
      $conn->close();
    }
    ?>

dbcon.php

      <?php
   if(session_id() == '' || !isset($_SESSION)) {
// session isn't started
         session_start();
      }  
     error_reporting(E_ALL & E_STRICT);
     ini_set('display_errors', '1');
     ini_set('log_errors', '0');
     ini_set('error_log', './');

     $dbhost = 'localhost';
     $dbuser = '------';
     $dbpass = '------';
     $dbtable = "-----";
     $conn = new mysqli($dbhost, $dbuser, $dbpass, $dbtable);

     if(!$conn ){
        die('Could not connect: ' . mysqli_error());
     }
  ?>

对不起,我对此并不陌生,我也应该更改本地主机吗?我在哪里可以找到正确的名字放在这里。

1 个答案:

答案 0 :(得分:-1)

声明

$stmt->bind_param('ss', $u, $p);

之后

  $u=$_POST['username'];
  $p=md5($_POST['password']);