登録順に積み上げたコードとmd5方式で暗号化したパスワードでSELECT文を使ってログインシステムを作っています。
DB構造
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| cdcol |
| mysql |
| performance_schema |
| phpmyadmin |
| shopdb |
| test |
| webauth |
+--------------------+
8 rows in set (0.00 sec)
mysql> show tables;
+------------------+
| Tables_in_shopdb |
+------------------+
| mst_product |
| mst_staff |
+------------------+
2 rows in set (0.00 sec)
mysql> show fields from mst_staff;
+-------------+-------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------------+-------------+------+-----+---------+----------------+
| code | int(11) | NO | PRI | NULL | auto_increment |
| staff_namae | varchar(20) | NO | | NULL | |
| staff_pass | varchar(32) | NO | | NULL | |
+-------------+-------------+------+-----+---------+----------------+
3 rows in set (0.01 sec)
ログイン入力
try
{
if (isset($_POST["staff_code"])) {
$staff_code = $_POST['staff_code'];
}
if (isset($_POST["staff_pass"])) {
$staff_pass = $_POST['staff_pass'];
}
$staff_code = htmlspecialchars($staff_code);
$staff_pass = htmlspecialchars($staff_pass);
$staff_pass=md5($staff_pass);
$dsn='mysql:dbname=shopdb;host=localhost';
$user='root';
$password='';
$dbh=new PDO($dsn,$user,$password);
$dbh->query('SETNAMES utf8');
$sql = 'SELECT staff_namae FROM mst_staff WEHRE code=? AND staff_pass=?';
$stmt = $dbh->prepare($sql);
$data[0]=$staff_code;
$data[1]=$staff_pass;
$stmt->execute($data);
$dbh = null;
print '<p>errorInfo='.print_r($stmt->errorInfo(), true)."</p>\n";
$rec = $stmt->fetch(PDO::FETCH_ASSOC);
if($rec==false)
{
print 'スタッフコードか名前が間違っています。<br />';
print '<h3><a href="staff_login.html">戻る</a></h3>';
}
else
{
header('Location:staff_top.php');
}
}
catch (Exception $e)
{
print 'ただいま障害により大変ご迷惑をおかけしております。';
exit();
}
?>
</body> </html> エラーインフォ errorInfo=Array ( [0] => 42000 [1] => 1064 [2] => You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'code='3' AND staff_pass='dc468c70fb574ebd07287b38d0d0676d'' at line 1 )スタッフコードか名前が間違っています。
私には、SQL文の1行目に宇文エラーがあるとしか分かりません。
どなたか間違いを教えていただけませんでしょうか
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2015/01/14 12:01