[英]need some help to solve php scripts after uploading to server [duplicate]
我在家里使用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
}
?>
警告:mysql_fetch_assoc()期望参数1是资源,在第41行的/home/hubertj/public_html/login_now.php中给出布尔值
这意味着查询返回false,因此您无法使用mysql_fetch_assoc。
您确定要正确连接到数据库吗? 表存在吗? 数据库名称是否正确?
调试dbConnect()
,您可以添加
if (!is_resource($conn))
die("Couldn't connect to MySQL");
然后mysql_error()
来获取错误。 我想你在连接时可能会错过mysql_select_db()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.