PHP代码在服务器中出错,但在本地运行良好 [英] PHP code gets errors in server but works fine in local

查看:67
本文介绍了PHP代码在服务器中出错,但在本地运行良好的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have my site running well on my local but when I uploaded it, the php code gets some error,

警告: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

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());
     }
  ?>

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

Sorry I am new to this, should I change the localhost too? where can I find the right name to put there.

推荐答案

声明

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

之后

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

这篇关于PHP代码在服务器中出错,但在本地运行良好的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆