私はこのリンクの内部にある事前にコーディングされたプロジェクトを使用して実験を行っていますhere。無効なSQLステートメント
私はxamppをmysqlのWebサーバーとして使用しています。このコードを持つ認証ページを実行するたびに:
<?php
include_once("zSessionStart.php");
include_once("zConfig.php");
include_once("zDB.php");
$password = $_REQUEST["password"];
$userID = $_REQUEST["userID"];
$isAdmin = false; //is administrator or not
$askDemo = false;
//authenticate the login data from login.php
$query="select userID, isAdmin, askDemo from $_usersTable where (password= '$password') and (userID='$userID');";
$rs=mysql_query($query) or die ("Invalid sql.");
if (mysql_num_rows($rs) > 0) //correct password
{
$array = mysql_fetch_array($rs);
if(strcmp($array["isAdmin"], "y")==0){
$isAdmin=true;
}
if(strcmp($array["askDemo"], "y")==0){
$askDemo=true;
}
if(!$isAdmin){
$query="select userID from usertests where userID='" . $userID . "'";
$rs2=mysql_query($query) or die ("Invalid sql.");
if(mysql_num_rows($rs2) > 0){ //already take test
$array2 = mysql_fetch_array($rs2);
echo "<h2> You have already taken the task. Please contact your administrator if you " .
" feel you need to re-take this task again.</h2>";
die();
}
}
$_SESSION['userID'] = $array["userID"];
session_unregister('loginErr');
if($isAdmin){
header("Location: transfer.php?" . SID);
}else{
if($askDemo){
header("Location:demo.php?" . SID);
}else{
header("Location: index.php?" . SID);
}
}
}
else
{
$_SESSION['loginErr'] = "true";
header("Location: login.php");
}
mysql_close($db);
?>
「Invalid sql。」というエラーが表示されます。私のデータベースの中には、ユーザーIDとパスワードなどの資格情報を持つユーザーと呼ばれるテーブルがあります。私はすでにユーザー名をadminとパスワードに設定しました。しかし、私は問題が何であるかを理解する運がなかった。
Gahです。現代のPHPでは 'mysql_ *'関数はなくなっています。彼らは単に存在しません。実際には、より現代的なチュートリアルでやり直すべきです。これには大きなセキュリティ上の脆弱性もあります。 – ceejayoz
あなたのテーブルが間違っているように見えるので、無効なsqlが来ています。$ _usersTable –
@ceejayoz、私はウェブ上にこれを設定しないので、セキュリティについてはあまり気にしません。私は古いPHP Webサーバーを使用することをお勧めしますか? – Yahyaotaif