-3

ユーザーがデータベースに存在するかどうかを確認するフォームを作成しようとしましたが、AJAX と sql の接続に問題があります。これらは私のコードです:

<!DOCTTYPE html>
<html lang="en">
<head>
<mete charset="UTF-8">
<title>Email client</title>
<script type="text/javascript">

function load(){
 if (window.XMLHttpRequest) {
     xmlhttp = new XMLHttpRequest();
 }else{
     xmlhttp = new ActiveXObject('Microsoft.XMLHTTP');
 }
 xmlhttp.onreadystatechange = function(){
     if (xmlhttp.readyState == 4 && xmlhttp.status == 200 ){
         document.getElementById('info').innerHTML = xmlhttp.responseText;
     }
 }
 xmlhttp.open('GET', 'checkuser.php', true);
 xmlhttp.send();

}

</script>
</head>

<body>

<form name="loginform" onclick="load();">

  Username : <input name="userID" type="text" id="userID"><br />
  Password : <input name="password" type="password" id="passWD"><br />
  <input type="submit" id="button" value="Get in there"> <br />
  <p>Don't have an account? <a href="register.html"> please register </a></p>
</form>

<div id="info"></div>


</body>

</html>

私のphp(checkuser.php):

<?php
$dbhost = 'localhost';
$dbuser = 'xxxx';
$dbpass = 'xxxx';
$dbname = 'xxxx';
$dbtable = 'xxxx';


$q=$_GET["userID"];
$p=$_GET["passWD"];

$con = mysql_connect($dbhost, $dbuser, $dbpass);
if (!$con)
 {
    die('Could not connect: ' . mysql_error());
 }
$dbselect = mysql_select_db($dbname,$con);

$sql="SELECT * FROM $dbtable WHERE userID='$q'";

$result = mysql_query($sql);


if (mysql_num_rows($result)==0) { 
    echo "not registered";
} else {
    while($row = mysql_fetch_array($result))
 {

 if (($row['passWD'])==$p) {
   echo "registered";
} else { echo "not registered";} 

}
} 
mysql_close($con);

?>
4

1 に答える 1

1

PHP は、2 つのクエリ文字列パラメーターが渡されることを期待しています (クエリ文字列でパスワードを送信しないでください。ログに記録される可能性があり、POST 要求を使用します)。ただし、JavaScript はクエリ文字列をまったく使用せずにスクリプトの URL を要求しているだけです。

おそらく、フォームからデータを取得し、ドキュメントのイベントではなくフォームのイベントloadを呼び出すように拡張したいと考えています。loadsubmitload

于 2013-01-16T13:26:36.313 に答える