0
我有一個登錄頁面和儀表盤頁面,用戶將登錄后土地(注:儀表板頁面是在另一個文件夾)....PHP PDO登錄...登錄錯誤後回聲電子郵件失敗
的login.php
<?php
include 'dbcon.php';
if(isset($_POST['sdsubmit'])){
$sdemail=$_POST['sdemail'];
$sdpassword=$_POST['sdpassword'];
$sql = "SELECT * FROM students WHERE email = ? && password= ?";
$query=$db->prepare($sql);
$query->execute(array($sdemail, $sdpassword));
$row = $query->fetch(PDO::FETCH_NUM);
if($row > 0){
session_start();
$sdemail=$_SESSION['sdemail'];
header("Location: student/index.php");
exit();
}
else{
echo "<script>alert('Sorry, email or password is incorrect. Please try again');
</script>";
}
}
形式(同一頁中的login.php)
<form id="login-form1" action="<?php echo $_SERVER["PHP_SELF"]; ?>" method="post" role="form" style="display: block;">
<div class="form-group">
<input type="email" name="sdemail" id="sdemail" required="required" tabindex="1" class="form-control" placeholder="Email" value="">
</div>
<div class="form-group">
<input type="password" name="sdpassword" id="sdpassword" tabindex="2" class="form-control" placeholder="Password">
</div>
<div class="form-group">
<div class="row">
<div class="col-sm-6 col-sm-offset-3">
<input type="submit" name="sdsubmit" id="login-submit" tabindex="4" class="form-control btn btn-login" value="Login">
</div>
</div>
</div>
</form>
儀表板(的index.php)
<?php
session_start();
echo $_SESSION['sdemail'];
dbcon.php(數據庫連接)
<?php
$errmsg_arr = array();
$errflag = false;
try{
$db=new PDO('mysql:host=localhost; dbname=internshala', 'root', '');
} catch (Exception $ex) {
echo "Sorry, cannot connect to database";
}
錯誤
說明:未定義指數:sdemail在C:\第3行的xampp \ htdocs \ Internshala \ student \ index.php
[PHP的可能重複: 「請注意:未定義的變量」,「通知:未定義索引「和」注意:未定義偏移量「](https://stackoverflow.com/questions/4261133/php-notice-undefined-variable-notice-undefined-index-and-notice-undef) – Qirel
您從未設置過'代碼中的任何地方都可以使用$ _SESSION ['sdemail']。 – Qirel
你好,我已經設置$ _SESSION ['sdemail'] = $ sdemail爲:'if($ row> 0){session_start(); $ sdemail = $ _ SESSION ['sdemail']; header(「Location:student/index.php」); exit(); }' –