【发布时间】:2018-11-25 08:56:55
【问题描述】:
我的网站在本地运行良好,但是当我上传它时,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());
}
?>
对不起,我是新手,我也应该更改本地主机吗?我在哪里可以找到合适的名称。
【问题讨论】:
-
使用包含/要求的绝对路径。我假设您的包含未加载,因此 $conn 未初始化。
-
require '../api/dbcon.php'; 检查此文件是否正确包含。
-
@LarsStegelitz 如何检查它是否已加载?我的意思是我检查了文件的位置,我认为应该没问题
-
@Nadee 抱歉,我不知道怎么做,你能教我吗?
-
var_dump(file_exists('../api/dbcon.php'), realpath('../api/dbcon.php'));
标签: php forms session mysqli server