Я загрузил сценарий онлайн для базовой системы, которая заставит пользователя войти в систему с именем пользователя admin и admin admin, но у сценария есть небольшая ошибка с страницей входа, где, похоже, есть переменная, которая не объявлена, я вижу, что переменная не объявлен из формы, но я не могу объявить таким образом, чтобы он мог работать. Мне нужен способ объявить переменную $position
из ввода формы, поэтому она хорошо работает с login.php. Вот ошибка
Примечание. Неопределенный индекс: позиция в C: \ Program Files \ EasyPHP-5.3.3 \ www \ preenrolmentsystem \ login.php в строке 20
Источник имеет 2 страницы один для login.php И один для формы, а именно formform.php
вот источник для login.php
<?php //Start session session_start(); //Connect to mysql server include('connect.php'); //Function to sanitize values received from the form. Prevents SQL injection function clean($str) { $str = @trim($str); if(get_magic_quotes_gpc()) { $str = stripslashes($str); } return mysql_real_escape_string($str); } //Sanitize the POST values $login = clean($_POST['id']); $password = clean($_POST['password']); $position = clean($_POST['position']); $result = mysql_query("SELECT * FROM user WHERE idnumber='$login' AND password='$password'"); while($row = mysql_fetch_array($result)) { $position = $row['position']; } if ($position=='admin') { //Create query $qry="SELECT * FROM admin WHERE idnum='$login' AND password='$password'"; $result=mysql_query($qry); //while($row = mysql_fetch_array($result)) // { // $level=$row['position']; // } //Check whether the query was successful or not if($result) { if(mysql_num_rows($result) > 0) { //Login Successful session_regenerate_id(); $member = mysql_fetch_assoc($result); $_SESSION['SESS_MEMBER_ID'] = $member['id']; session_write_close(); //if ($level="admin"){ header("location: admin/index.php"); exit(); }else { //Login failed header("location: loginform.php"); exit(); } }else { die("Query failed"); } } if ($position=='student') { //Create query $qry="SELECT * FROM prereg WHERE idnumber='$login' AND password='$password'"; $result=mysql_query($qry); //while($row = mysql_fetch_array($result)) // { // $level=$row['position']; // } //Check whether the query was successful or not if($result) { if(mysql_num_rows($result) > 0) { //Login Successful session_regenerate_id(); $member = mysql_fetch_assoc($result); $_SESSION['SESS_MEMBER_ID'] = $member['id']; $_SESSION['SESS_FIRST_NAME'] = $member['idnumber']; session_write_close(); //if ($level="admin"){ header("location: student/profile.php"); exit(); }else { //Login failed header("location: loginform.php"); exit(); } }else { die("Query failed"); } } if ($position=='Casher') { //Create query $qry="SELECT * FROM casher WHERE idnumber='$login' AND password='$password'"; $result=mysql_query($qry); //while($row = mysql_fetch_array($result)) // { // $level=$row['position']; // } //Check whether the query was successful or not if($result) { if(mysql_num_rows($result) > 0) { //Login Successful session_regenerate_id(); $member = mysql_fetch_assoc($result); $_SESSION['SESS_MEMBER_ID'] = $member['id']; $_SESSION['SESS_FIRST_NAME'] = $member['idnumber']; session_write_close(); //if ($level="admin"){ header("location: casher/index.php"); exit(); }else { //Login failed header("location: loginform.php"); exit(); } }else { die("Query failed"); } } if ($position=='teacher') { //Create query $qry="SELECT * FROM teacher WHERE idnumber='$login' AND password='$password'"; $result=mysql_query($qry); //while($row = mysql_fetch_array($result)) // { // $level=$row['position']; // } //Check whether the query was successful or not if($result) { if(mysql_num_rows($result) > 0) { //Login Successful session_regenerate_id(); $member = mysql_fetch_assoc($result); $_SESSION['SESS_MEMBER_ID'] = $member['id']; $_SESSION['SESS_FIRST_NAME'] = $member['idnumber']; session_write_close(); //if ($level="admin"){ header("location: teacher/index.php"); exit(); }else { //Login failed header("location: loginform.php"); exit(); } }else { die("Query failed"); } }
в<?php //Start session session_start(); //Connect to mysql server include('connect.php'); //Function to sanitize values received from the form. Prevents SQL injection function clean($str) { $str = @trim($str); if(get_magic_quotes_gpc()) { $str = stripslashes($str); } return mysql_real_escape_string($str); } //Sanitize the POST values $login = clean($_POST['id']); $password = clean($_POST['password']); $position = clean($_POST['position']); $result = mysql_query("SELECT * FROM user WHERE idnumber='$login' AND password='$password'"); while($row = mysql_fetch_array($result)) { $position = $row['position']; } if ($position=='admin') { //Create query $qry="SELECT * FROM admin WHERE idnum='$login' AND password='$password'"; $result=mysql_query($qry); //while($row = mysql_fetch_array($result)) // { // $level=$row['position']; // } //Check whether the query was successful or not if($result) { if(mysql_num_rows($result) > 0) { //Login Successful session_regenerate_id(); $member = mysql_fetch_assoc($result); $_SESSION['SESS_MEMBER_ID'] = $member['id']; session_write_close(); //if ($level="admin"){ header("location: admin/index.php"); exit(); }else { //Login failed header("location: loginform.php"); exit(); } }else { die("Query failed"); } } if ($position=='student') { //Create query $qry="SELECT * FROM prereg WHERE idnumber='$login' AND password='$password'"; $result=mysql_query($qry); //while($row = mysql_fetch_array($result)) // { // $level=$row['position']; // } //Check whether the query was successful or not if($result) { if(mysql_num_rows($result) > 0) { //Login Successful session_regenerate_id(); $member = mysql_fetch_assoc($result); $_SESSION['SESS_MEMBER_ID'] = $member['id']; $_SESSION['SESS_FIRST_NAME'] = $member['idnumber']; session_write_close(); //if ($level="admin"){ header("location: student/profile.php"); exit(); }else { //Login failed header("location: loginform.php"); exit(); } }else { die("Query failed"); } } if ($position=='Casher') { //Create query $qry="SELECT * FROM casher WHERE idnumber='$login' AND password='$password'"; $result=mysql_query($qry); //while($row = mysql_fetch_array($result)) // { // $level=$row['position']; // } //Check whether the query was successful or not if($result) { if(mysql_num_rows($result) > 0) { //Login Successful session_regenerate_id(); $member = mysql_fetch_assoc($result); $_SESSION['SESS_MEMBER_ID'] = $member['id']; $_SESSION['SESS_FIRST_NAME'] = $member['idnumber']; session_write_close(); //if ($level="admin"){ header("location: casher/index.php"); exit(); }else { //Login failed header("location: loginform.php"); exit(); } }else { die("Query failed"); } } if ($position=='teacher') { //Create query $qry="SELECT * FROM teacher WHERE idnumber='$login' AND password='$password'"; $result=mysql_query($qry); //while($row = mysql_fetch_array($result)) // { // $level=$row['position']; // } //Check whether the query was successful or not if($result) { if(mysql_num_rows($result) > 0) { //Login Successful session_regenerate_id(); $member = mysql_fetch_assoc($result); $_SESSION['SESS_MEMBER_ID'] = $member['id']; $_SESSION['SESS_FIRST_NAME'] = $member['idnumber']; session_write_close(); //if ($level="admin"){ header("location: teacher/index.php"); exit(); }else { //Login failed header("location: loginform.php"); exit(); } }else { die("Query failed"); } }
?>
и loginform.php
<?php //Start session session_start(); //Unset the variables stored in session unset($_SESSION['SESS_MEMBER_ID']); unset($_SESSION['SESS_FIRST_NAME']); unset($_SESSION['SESS_LAST_NAME']); ?> <html> <head> <title> </title> <link rel="stylesheet" href="css/main.css" /> <style type="text/css"> <!-- .ed{ border-style:solid; border-width:thin; border-color:#00CCFF; padding:5px; margin-bottom: 4px; } #button1{ text-align:center; font-family:Arial, Helvetica, sans-serif; border-style:solid; border-width:thin; border-color:#00CCFF; padding:5px; background-color:#00CCFF; height: 34px; } --> </style> </head> <body> <div id="mainwrapper"> <div id="header"> <img src="images/amuni.jpg"> </div> <div id="menu"> <ul> <li> <a href="index.php">Home</a> </li> <li> <a href="loginform.php">Login</a> </li> <li> <a href="pre_reg.php">Student Pre Registration</a> </li> <li> <a href="aboutus.php">About Us</a> </li> <li> <a href="help.php">Help</a> </li> <div class="clearfix"></div> </ul> </div> <div id="main" style="padding:20px; text-align:justify; font-family:arial;"> <form action="login.php" method="post"> ID Number<br> <input type="text" name="id" class="ed"><br> Password<br> <input type="password" name="password" class="ed"><br> <input type="submit" value="Login" id="button1"> </form> </div> <div id="footer"> </div> <div class="clearfix"></div> </div> </body> </html>
с<?php //Start session session_start(); //Unset the variables stored in session unset($_SESSION['SESS_MEMBER_ID']); unset($_SESSION['SESS_FIRST_NAME']); unset($_SESSION['SESS_LAST_NAME']); ?> <html> <head> <title> </title> <link rel="stylesheet" href="css/main.css" /> <style type="text/css"> <!-- .ed{ border-style:solid; border-width:thin; border-color:#00CCFF; padding:5px; margin-bottom: 4px; } #button1{ text-align:center; font-family:Arial, Helvetica, sans-serif; border-style:solid; border-width:thin; border-color:#00CCFF; padding:5px; background-color:#00CCFF; height: 34px; } --> </style> </head> <body> <div id="mainwrapper"> <div id="header"> <img src="images/amuni.jpg"> </div> <div id="menu"> <ul> <li> <a href="index.php">Home</a> </li> <li> <a href="loginform.php">Login</a> </li> <li> <a href="pre_reg.php">Student Pre Registration</a> </li> <li> <a href="aboutus.php">About Us</a> </li> <li> <a href="help.php">Help</a> </li> <div class="clearfix"></div> </ul> </div> <div id="main" style="padding:20px; text-align:justify; font-family:arial;"> <form action="login.php" method="post"> ID Number<br> <input type="text" name="id" class="ed"><br> Password<br> <input type="password" name="password" class="ed"><br> <input type="submit" value="Login" id="button1"> </form> </div> <div id="footer"> </div> <div class="clearfix"></div> </div> </body> </html>
с<?php //Start session session_start(); //Unset the variables stored in session unset($_SESSION['SESS_MEMBER_ID']); unset($_SESSION['SESS_FIRST_NAME']); unset($_SESSION['SESS_LAST_NAME']); ?> <html> <head> <title> </title> <link rel="stylesheet" href="css/main.css" /> <style type="text/css"> <!-- .ed{ border-style:solid; border-width:thin; border-color:#00CCFF; padding:5px; margin-bottom: 4px; } #button1{ text-align:center; font-family:Arial, Helvetica, sans-serif; border-style:solid; border-width:thin; border-color:#00CCFF; padding:5px; background-color:#00CCFF; height: 34px; } --> </style> </head> <body> <div id="mainwrapper"> <div id="header"> <img src="images/amuni.jpg"> </div> <div id="menu"> <ul> <li> <a href="index.php">Home</a> </li> <li> <a href="loginform.php">Login</a> </li> <li> <a href="pre_reg.php">Student Pre Registration</a> </li> <li> <a href="aboutus.php">About Us</a> </li> <li> <a href="help.php">Help</a> </li> <div class="clearfix"></div> </ul> </div> <div id="main" style="padding:20px; text-align:justify; font-family:arial;"> <form action="login.php" method="post"> ID Number<br> <input type="text" name="id" class="ed"><br> Password<br> <input type="password" name="password" class="ed"><br> <input type="submit" value="Login" id="button1"> </form> </div> <div id="footer"> </div> <div class="clearfix"></div> </div> </body> </html>
с<?php //Start session session_start(); //Unset the variables stored in session unset($_SESSION['SESS_MEMBER_ID']); unset($_SESSION['SESS_FIRST_NAME']); unset($_SESSION['SESS_LAST_NAME']); ?> <html> <head> <title> </title> <link rel="stylesheet" href="css/main.css" /> <style type="text/css"> <!-- .ed{ border-style:solid; border-width:thin; border-color:#00CCFF; padding:5px; margin-bottom: 4px; } #button1{ text-align:center; font-family:Arial, Helvetica, sans-serif; border-style:solid; border-width:thin; border-color:#00CCFF; padding:5px; background-color:#00CCFF; height: 34px; } --> </style> </head> <body> <div id="mainwrapper"> <div id="header"> <img src="images/amuni.jpg"> </div> <div id="menu"> <ul> <li> <a href="index.php">Home</a> </li> <li> <a href="loginform.php">Login</a> </li> <li> <a href="pre_reg.php">Student Pre Registration</a> </li> <li> <a href="aboutus.php">About Us</a> </li> <li> <a href="help.php">Help</a> </li> <div class="clearfix"></div> </ul> </div> <div id="main" style="padding:20px; text-align:justify; font-family:arial;"> <form action="login.php" method="post"> ID Number<br> <input type="text" name="id" class="ed"><br> Password<br> <input type="password" name="password" class="ed"><br> <input type="submit" value="Login" id="button1"> </form> </div> <div id="footer"> </div> <div class="clearfix"></div> </div> </body> </html>
любой ввод оценивается