我在家里使用 xampp……下周我需要在学校展示我的工作,因此我决定上传到免费的托管服务器。在我的 xampp 机器上,它工作得非常好,但是一旦我将数据库和我的文件上传到public_html,这些文件就不能再正常工作了。
我的网站
这是登录页面,但是在我使用准确的用户名和密码登录后,出现了几个错误,例如
Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in /home/hubertj/public_html/login_now.php on line 41
Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in /home/hubertj/public_html/login_now.php on line 43
Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in /home/hubertj/public_html/login_now.php on line 51
Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in /home/hubertj/public_html/login_now.php on line 59
Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in /home/hubertj/public_html/login_now.php on line 67
Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in /home/hubertj/public_html/login_now.php on line 75
Warning: Cannot modify header information - headers already sent by (output started at /home/hubertj/public_html/login_now.php:41) in /home/hubertj/public_html/login_now.php on line 86
但是在我的 xampp 机器上它运行顺利。因此我所做的是我在 sql 界面中尝试了查询,它也可以正常工作。我只是不明白上传到服务器时错过了什么步骤。这是我第一次用数据库上传网站。非常感谢。
发生错误的 login_now.php 代码:
<?php session_start(); ?>
<?php include("Connections/database.php");?>
<?php
$myeid = $_POST['logineid'];
$mypassword = $_POST['password'];
$conn = dbConnect(); //get connected to database
//successful?
if (!$conn)
die("Couldn't connect to MySQL");
$query = "select * from emp where EID = '$myeid' and PASS = '$mypassword'";
//run the query
$result = mysql_query($query, $conn);
$row = mysql_fetch_assoc($result);
if (mysql_num_rows($result) > 0 and $row['POSITION']=="manager") //found a record whose position is manager?
{
$_SESSION['eid'] = $myeid; //remember name as a session variable
$_SESSION['password'] = $mypassword; //remember password as a session variable
$_SESSION['start'] = time(); // taking now logged in time
$_SESSION['expire'] = $_SESSION['start'] + (60 * 60) ; // ending a session in 60 minutes from the starting time
header('Location: manager/welmanager.php'); //redirect user to index
}
elseif (mysql_num_rows($result) > 0 and $row['POSITION']=="staff") //found a record whose position is staff?
{
$_SESSION['eid'] = $myeid;
$_SESSION['password'] = $mypassword;
$_SESSION['start'] = time();
$_SESSION['expire'] = $_SESSION['start'] + (60 * 60) ;
header('Location: staff/welstaff.php'); //redirect user to index
}
elseif (mysql_num_rows($result) > 0 and $row['POSITION']=="nurse")
{
$_SESSION['eid'] = $myeid;
$_SESSION['password'] = $mypassword;
$_SESSION['start'] = time();
$_SESSION['expire'] = $_SESSION['start'] + (60 * 60) ;
header('Location: nurse/welnurse.php'); //redirect user to index
}
elseif (mysql_num_rows($result) > 0 and $row['POSITION']=="train")
{
$_SESSION['eid'] = $myeid;
$_SESSION['password'] = $mypassword;
$_SESSION['start'] = time();
$_SESSION['expire'] = $_SESSION['start'] + (60 * 60) ;
header('Location: train/weltrain.php'); //redirect user to index
}
elseif (mysql_num_rows($result) > 0 and $row['POSITION']=="hr")
{
$_SESSION['eid'] = $myeid;
$_SESSION['password'] = $mypassword;
$_SESSION['start'] = time();
$_SESSION['expire'] = $_SESSION['start'] + (60 * 60) ;
header('Location: hr/welhr.php'); //redirect user to index
}
else
{
$_SESSION['form_error'] = "Invalid Employee ID or Password";
header('Location: login.php'); //kick back to login
}
dbDisconnect($conn);
?>
我无法弄清楚上传到服务器时错过的步骤。希望可以有人帮帮我。谢谢。
我的数据库脚本在这里:
<?php
function dbConnect()
{
$host = "mysql16.000webhost.com"; //location of MySQL server
$username = "a5523583_root"; //username to access MySQL Server
$password = "cailing8195"; //password to access MySQL Server
$database = "a5523583_jlr"; //database to access
//try to get connected
$conn = mysql_connect ($host, $username, $password);
//try to wselect the database
$select = mysql_select_db ($database, $conn);
return $conn;
}
function dbDisconnect($conn)
{
mysql_close($conn); //get disconnected from DB
}
?>