我試圖將表單動作「轉換」爲ajax調用。 我的形式:ajax調用並驗證php中的電子郵件
<!-- <form method="POST" onSubmit="return doSubmitLogic()" action="action.scripts.php" >
<input type="hidden" name="actiune" value="login" />
<div>
<label> Email </label>
<input type="email" name = "email" id="email" /><span id="emailErr"></span >
</div>
<div>
<label> Password </label>
<input type="password" name = "password" id="password" /> <span id="passErr"></span >
</div>
<div>
<input id ="submitBtn" type="submit" name="button" value="Send"/>
</div>
而我試圖用我的AJAX做:
$(document).ready(function(){
$("#submitBtn").click(function(e){
e.preventDefault();
$.ajax({
type: "POST",
url: "functions.php",
data: {
Email: $("#email").val(),
Password: $("#password").val(),
},
success: function(result){
alert(result);
},
error: function (error){
alert("Error");
}
});
});
});
也是我的一段代碼 「的functions.php」 是由組成許多檢查行動是否具有特定的價值,如果是這樣做的話。所以:
if ($_POST['actiune']==="login") {
$email = $_POST['email'];
$password = $_POST['password'];
$encript_pass = md5($password);
$query = "select * from user where email='$email' and password='$encript_pass'";
$result = mysql_query($query) or die ("Error in query: $query " . mysql_error());
$row = mysql_fetch_array($result);
if (!filter_var($email, FILTER_VALIDATE_EMAIL) === false) {
echo("$email is a valid email address");
} else {
echo("$email is not a valid email address");
}
}
當我運行它時,它給我一個警告說錯誤。任何syggestions?
你的第一個也是最大的錯誤是,你把未經過濾的郵件發送到你的sql語句!這樣做非常不安全!你的錯誤說了什麼? – eisbehr
沒什麼。它說只是錯誤。我認爲它來自ajax的錯誤 – johnwilliam25
***你真的不應該使用[MD5密碼哈希](http://security.stackexchange.com/questions/19906/is-md5-considered-insecure)** *並且您確實應該使用PHP的[內置函數](http://jayblanchard.net/proper_password_hashing_with_PHP.html)來處理密碼安全性。在散列之前,請確保你[不要越過密碼](http://stackoverflow.com/q/36628418/1011527)或使用其他任何清理機制。這樣做會改變密碼並導致不必要的附加編碼。 –