0

重複の可能性:
警告:mysql_fetch_ *はパラメーター1がリソースであると想定しており、ブール値でエラーが発生します

私は自宅で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
}
?>
4

2 に答える 2