login_check.phpにおけるエラー内容
Notice: Undefined variable: manager_flg in /home/a_yonamine/public_html/login_check.php on line 68 Notice: Undefined variable: manager_flg in /home/a_yonamine/public_html/login_check.php on line 72 Notice: Undefined variable: shain_id in /home/a_yonamine/public_html/login_check.php on line 107 Notice: Undefined variable: shain_mei in /home/a_yonamine/public_html/login_check.php on line 109
login.html
<html> <head> <title>ログイン画面</title> </head> <body> <div style="width:1200px"> <table style='border:cyan;border-style:solid;margin-left:300px;margin-right:300px;width:600px;text-align:center'> <tr><td colspan="2" style="color:red"><###ERROR###></td></tr> <tr> <td colspan="2"> ログイン </td> </tr> <form method="post" action="./login_check.php"> <tr> <td style="width:30%"> 社員番号 </td> <td> <input type="text" style="width:100%" id="account" name="account" placeholder="アカウントを入力してください"></input> </td> </tr> <tr> <td> パスワード </td> <td> <input type="password" style="width:100%" id="password" name="password" placeholder="パスワードを入力してください"></input> </td> </tr> <tr> <td colspan="2"> <input type="submit" style="width:200px" value="送信"></input> </td> </tr> </form> </table> </div> </body> </html>
login_check.php
<?php // 設定ファイルの読み込み require_once('./database_config.php'); //Post Parameter $shain_bango=$_POST['account']; $password=$_POST['password']; //Database connect $link=mysqli_connect(DB_SERVER,DB_ACCOUNT_ID,DB_ACCOUNT_PW,DB_NAME); if (!$link) { echo "Error: Unable to connect to MySQL." . PHP_EOL; echo "Debugging errno: " . mysqli_connect_errno() . PHP_EOL; echo "Debugging error: " . mysqli_connect_error() . PHP_EOL; exit; } mysqli_set_charset($link,"utf8"); //Query $query='select shain_id, shain_mei, manager_flg from shain_info where shain_bango="'.$shain_bango.'" and password="'.$password.'"'; //Execute if ($result = mysqli_query($link, $query)) { $i=0; while ($row = mysqli_fetch_row($result)) { $shain_id[$i] = $row[0]; $shain_mei[$i] = $row[1]; $manager_flg[$i] = $row[2]; // echo $manager_flg[0]; $i++; } mysqli_free_result($result); if ($manager_flg[0]==="1"){ header('location: ./employerlist.php'); }else if ($manager_flg[0]!="1"){ header('locaion: ./employerdetail.php'); }else { move_login(); } } else { // if error, move login move_login(); } // keep login information between screens session_save_path('/home/a_yonamine/session/'); session_start(); // inititalize session $_SESSION = array(); $_SESSION['shain_id'] = $shain_id[0]; $_SESSION['shain_mei'] = $shain_mei[0]; mysqli_close($link); exit; function move_login() { header('location: ./login.php?em=1'); exit; } ?>
データーベースの構成
mysql> desc shain_info; +--------------------+-------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +--------------------+-------------+------+-----+---------+----------------+ | shain_id | int(11) | NO | PRI | NULL | auto_increment | | shain_bango | char(8) | NO | | NULL | | | password | char(8) | NO | | NULL | | | shain_mei | varchar(20) | NO | | NULL | | | shain_shozokubu | varchar(40) | NO | | NULL | | | manager_flg | char(1) | NO | | NULL | | | shain_nyuushanen | int(4) | NO | | NULL | | | shain_nyuushatsuki | int(2) | NO | | NULL | | | shain_nyuushabi | int(2) | NO | | NULL | | | shain_taishanen | int(4) | YES | | NULL | | | shain_taishatsuki | int(2) | YES | | NULL | | | shain_taishabi | int(2) | YES | | NULL | | | shain_jusho | text | YES | | NULL | | +--------------------+-------------+------+-----+---------+----------------+ 13 rows in set (0.02 sec)
格納されているデータ
mysql> select * from shain_info; +----------+-------------+----------+--------------------+-----------------+-------------+------------------+--------------------+-----------------+-----------------+-------------------+----------------+--------------------+ | shain_id | shain_bango | password | shain_mei | shain_shozokubu | manager_flg | shain_nyuushanen | shain_nyuushatsuki | shain_nyuushabi | shain_taishanen | shain_taishatsuki | shain_taishabi | shain_jusho | +----------+-------------+----------+--------------------+-----------------+-------------+------------------+--------------------+-----------------+-----------------+-------------------+----------------+--------------------+ | 1 | 1 | Akio4274 | 与那嶺あきお | IT支援 | 0 | 2019 | 1 | 30 | 2019 | 2 | 30 | 千葉県千葉市 | | 2 | 1 | Taro4274 | 山田太郎 | IT支援 | 0 | 2019 | 1 | 30 | 2020 | 2 | 30 | 東京都港区 | +----------+-------------+----------+--------------------+-----------------+-------------+------------------+--------------------+-----------------+-----------------+-------------------+----------------+--------------------+ 2 rows in set (0.00 sec)
PHPのヴァージョン
PHP 5.4.45 (cli) (built: Sep 11 2015 21:23:18) Copyright (c) 1997-2014 The PHP Group Zend Engine v2.4.0, Copyright (c) 1998-2014 Zend Technologies
困っている事
現在従業員管理システムを作成しています。
login.htmlで表示されたテキストボックスに社員番号とパスワードを入力し、入力されたデータを元にそれぞれ、社員詳細もしくは社員一覧ページのどちらに遷移するかを振り分けるのがlogin_cehck.phpで書いてあるコードの役割なのですが、上記のようにエラーが出ます。
エラー内容はlogin_check.phpで$manager_flg, $shain_mei, $shain_idの三つの変数を定義しているのですが、68,72, 107,109行では変数がうまく反映されていないようです。
解決したい事
68,72, 107,109行目でも変数が反映されるようにしたいです。
色々試行錯誤しましたがわかりません。
お手数ですが、どなたかわかる方ご教授願います。
何か情報が不足していたら何なりとお申し付けください。
回答3件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/02/25 04:41