2016-11-15 14 views
0

こんにちは、私はこの問題を解決するためにPHPとhtmlの初心者です。それは私にこのエラーWarning: oci_num_rows() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\login.php on line 15PHP-HTML-ORACLE私はスクリプトでエラーが発生しました

を与える

が、これは私のコードです:

<?php 
session_start(); 
// connect to database 
if (isset($_POST['login_btn'])) { 
    $username =$_POST['username']; 
    $password =$_POST['password']; 
    $conn = oci_connect('socialdb', '12345', 'localhost/XE'); 
    if (!$conn) { 
     $e = oci_error(); 
     trigger_error(htmlentities($e['message'], ENT_QUOTES), E_USER_ERROR); 
    } 
    $password = md5($password); // remember we hashed password before storing last time 
    $sql = oci_parse($conn,"SELECT * FROM ACCOUNT WHERE username='$username' AND password='$password'"); 
    $result =oci_execute($sql); 
    if (oci_num_rows($result) == 1) { 
     $_SESSION['message'] = "You are now logged in"; 
     $_SESSION['username'] = $username; 
     header("location: home.php"); //redirect to home page 
    } else{ 
     $_SESSION['message'] = "Username/password combination incorrect"; 
    } 
} 
?> 

UPDATE:

<!DOCTYPE html> 
 
<html> 
 
<head> 
 
\t <title>Register, login and logout user php oracle</title> 
 
\t <link rel="stylesheet" type="text/css" href="stylea.css"> 
 
</head> 
 
<body> 
 
<div class="header"> 
 
\t <h1>Register, login and logout user php oracle</h1> 
 
</div> 
 
<?php 
 
\t if (isset($_SESSION['message'])) { 
 
\t \t echo "<div id='error_msg'>".$_SESSION['message']."</div>"; 
 
\t \t unset($_SESSION['message']); 
 
\t } 
 
?> 
 

 

 
<form method="post" action="login.php"> 
 
\t <table> 
 
\t \t <tr> 
 
\t \t \t <td>Username:</td> 
 
\t \t \t <td><input type="text" name="username" class="textInput"></td> 
 
\t \t </tr> 
 

 
\t \t <tr> 
 
\t \t \t <td>Password:</td> 
 
\t \t \t <td><input type="password" name="password" class="textInput"></td> 
 
\t \t </tr> 
 

 
\t \t <tr> 
 
\t \t \t <td></td> 
 
\t \t \t <td><input type="submit" name="login_btn" value="Login"></td> 
 
\t \t </tr> 
 
\t </table> 
 
</form> 
 
</body> 
 
</html>

:たぶん、問題はHTML形式でありますありがとう、ごめんなさい私の悪い英語。

+0

デシベル最初の「SELECT *口座からWHEREユーザー名= '$上のあなたのSQLを確認してくださいためthis linkを参照し、oci_executeはブール値を返しますので、その後、注意を払って、最初のクエリ結果の妥当性をチェックしますusername 'とpassword =' $ password '"と入力します。指定されたユーザーとパスワードの結果を取得しているかどうかを確認してください。またはuは、このSQLのために1つ以上の行を持つかもしれません。 –

+0

1は私のテーブルに1行だけあり、それは動作します。 –

答えて

1

てみ例

$result = oci_execute($sql); 
if ($result) { 
    if (oci_num_rows($sql) == 1) { 
     $_SESSION['message'] = "You are now logged in"; 
     $_SESSION['username'] = $username; 
     header("location: home.php"); //redirect to home page 
    } else{ 
     $_SESSION['message'] = "Username/password combination incorrect"; 
    } 
} else { 
    $_SESSION['message'] = "Query error"; 
} 
+0

私はまだこの警告を持っています:oci_num_rows()は、パラメータ1がリソースであることを期待しています。行16のC:\ xampp \ htdocs \ login.phpに与えられたブール値です。 –

+0

それは私には間違っている、私は助けることができますか?:DIは、選択されたフォームをデータベースと試してみました –

+0

'$ username'と' $ password'変数の内容は正しいですか?あなたは 'oci_num_rows()'が1より大きい数値を返さないと確信していますか? – lubilis

関連する問題