這是我第一次驗證,我有已經花了無數的時間在這個最困難的時候。我有一個需要驗證的註冊表單,我已經爲此嘗試了2個腳本。效果最好的腳本可以看到下面:但是每一次我嘗試呼應的錯誤消息在我的文本字段,以顯示我收到以下錯誤信息:PHP的表單驗證錯誤
注意:未定義的變量:c_email在/應用上線/MAMP/htdocs/PhpProject2/Reg_1.php
說明:未定義變量:c_emailErr在/Applications/MAMP/htdocs/PhpProject2/Reg_1.php線163
說明:未定義變量:/ Applicat中的c_pass1Err上線離子/ MAMP/htdocs中/ PhpProject2/Reg_1.php 169
C_emailErr和c_pass1Err都定義。
任何幫助,將不勝感激。
HTML
<section class="container">
<form id="myform " class="Form" method="POST" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>" accept-charset="utf-8">
<!--<div id="first">-->
<input type="email" id="email" name="email" placeholder="Email Address" value="<?= $c_email ?>" required >
<br>
<span class="error"><?php echo $c_emailErr; ?></span>
<br>
<figure>
<input class ="login-field" type="password" id="pass1" name="pass1" value="<?= $c_pass1 ?>" placeholder="Password" maxlength="30" required>
<br>
<span class="error"><?php echo $c_pass1Err; ?></span>
<br>
<input class ="login-field" type="password" id="pass2" name="pass2" value="" placeholder=" Confirm password" maxlength="30" required><!--<span class="error"><?php //echo $c_pass2Err; ?></span>-->
<div id="messages"></div>
</figure>
<p class="remember_me">
</p>
<input type="submit" name="submit" value="Register" id="submit_button" class="btn btn-default">
<br>
</form>
<?php
?>
</form>
</section>
PHP
<?php
if (isset($_POST['submit'])) {
$c_email = $_POST['email'];
$c_pass1 = $_POST['pass1'];
$c_pass2 = $_POST['pass2'];
$c_emailErr = $c_pass1Err = $c_pass2Err = "";
//Checking the email address
if (!filter_var($c_email, FILTER_VALIDATE_EMAIL) === false) {
echo ("<b id='email'> This is a valid email address </b>");
} else {
echo ("<b id='email'> Email is not a valid email address</b>");
}
if (strlen($c_pass1) <= '8') {
echo "<b>Your Password Must Contain At Least 8 Characters!</br>";
//check passwords
} elseif ($c_pass1 == $c_pass2) {
$q = "INSERT INTO Cus_Register(Cus_Email,Cus_Password,Cus_confirm_password) VALUES (?,?,?)";
$stmt = mysqli_prepare($dbc, $q);
//new
// $stmt = mysqli_prepare($dbc, $insert_c);
//debugging
//$stmt = mysqli_prepare($dbc, $insert_c) or die(mysqli_error($dbc));
mysqli_stmt_bind_param($stmt, 'sss', $c_email, $c_pass1, $c_pass2);
if ($q) {
echo "<script> alert('registration sucessful')</script>";
}
} else {
echo "<b>Oops! Your passwords do not </b>";
}
}
?>
[PHP: 「注意:未定義變量」 和 「通知:未定義的索引」]的可能的複製(http://stackoverflow.com/questions/4261133/php-notice-undefined-variable-and-notice -undefined-index) – Qirel
PHP和HTML代碼是否包含在同一個文件中? OMG! – apokryfos