JS: 的JS爲email
領域的客戶端驗證爲什麼這不提交數據庫的價值?
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"> </script>
<script type="text/javascript" src="src/js/validate.js"> </script>
<script type="text/javascript">
$.validator.setDefaults({
submitHandler: function() { alert("submitted!"); }
});
$().ready(function() {
// validate alphaRegister form on keyup and submit
$("#alphaRegister").validate({
rules: {
email: {
required: true,
email: true
}
},
messages: {
email: "*"
}
});
});
</script>
HTML 形式
<form id="alphaRegister" action="src/php/newSubscriber.php" method="post">
<input type="email" name="email" id="cemail" value="" class="required" />
<div style="float:right; margin:0 5px 2px 0;"><input type="submit" id="submit" name="submit" value="" /></div>
</form>
當我進入一個[email protected],它只是說submitted!!
P HP文件 文件處理HTML
<?php
$host="localhost"; // Host name
$username="myuser"; // Mysql username
$username2="root"; #localhost
$password="mypass"; // Mysql password
$password2=""; #localhost
$db_name="mydbname"; // Database name
$tbl_name="mydbtblname"; // Table name
// Connect to server and select databse.
mysql_connect("$host", "$username2", "$password2")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot connect to database");
/* Obliterate bad input */
$goodEmail = mysql_real_escape_string($_POST['email']);
$sql= "INSERT INTO alphaSubscribers (alphaSEmAddr) VALUES('$goodEmail')";
$result = mysql_query($sql);
if (!$result) {
die('Invalid Email, please retry.');
}
else {
header('Location: /index.php') ;
echo "<meta HTTP-EQUIV='REFRESH' content='0; url=/index.php'>";
}
?>
任何的輸入看看有什麼林做錯了什麼?
你得到什麼錯誤?在這裏粘貼 – 2012-01-29 21:07:44
添加後,它不會提交到數據庫.. – CodeTalk 2012-01-29 21:43:55