我試圖做的邏輯是有效:更改輸入的背景顏色,如果輸入的值是數據庫
input field starts white (Normal);
after somebody finish typing, if the email does not exists, the input gets light red;
if the email exists in the database, the input becomes white again;
我有這樣的代碼:
的index.php
<?php
include 'my database connection page';
include 'page that return me an array with all the emails';
?>
<form method="POST">
<input type="text" name="email" id="email_field" onFocus="changeColorEmail(this)">
<input type="submit">
</form>
scripts.js中
function changeColorEmail(which) {
which.value = which.value.split(' ').join('')
if (which.value == "<? echo $user_data['user_email'] ?>") {
which.style.background = '#ffffff';
}else {
which.style.background = "#ffebe8";
}
}
任何想法表示讚賞!
user.php的(包含驗證是否在數據庫中存在的電子郵件功能)
function email_exists($email){
return (mysql_result(mysql_query("SELECT COUNT(user_id) FROM user WHERE user_email = '$email'"), 0) == 1) ? true : false;
}
你錯過了'回聲'在'if'並且還引用了 - >'「<?echo $ user_data ['user_email']?」'' – Engineer
@Engineer謝謝!它說的語法錯誤.. – Andre
sry ..剛剛更新我的帖子! – Andre