gpt4 book ai didi

php - 上传到服务器后需要一些帮助来解决 php 脚本

转载 作者:行者123 更新时间:2023-11-29 08:55:30 27 4
gpt4 key购买 nike

这个问题已经存在:




9年前关闭。




Possible Duplicate:
Warning: mysql_fetch_* expects parameter 1 to be resource, boolean given error



我在家里使用 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
}
?>

最佳答案

Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in /home/hubertj/public_html/login_now.php on line 41



这意味着查询返回 false,因此您不能使用 mysql_fetch_assoc。

您确定您正确连接到数据库吗?表存在吗?数据库名称是否正确?

关于php - 上传到服务器后需要一些帮助来解决 php 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10074223/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com