我一直坚持这个比我打算这么简单的事情,任何想法为什么打算验证不工作的时间?简单的Javascript验证 - 不工作
if(isset($_POST['submit'])){
/* Posted Values from Initial Form */
$descEmail = $_POST['email'];
$uniqueID = $_POST['name'];
/* Check to see if the Email Provided is already in use */
$result = mysql_query("SELECT * FROM Table WHERE Email = '$descEmail'");
if(mysql_num_rows($result) == 0) {
echo 'success';
} else {
echo '<script type="text/javascript"> emailInvalid() </script>';
}
}
的JavaScript:
<script type="text/javascript">
function emailInvalid(){
document.getElementById('UserEmail').style.borderColor='#CC0033';
document.getElementById('UserEmail').style.border='solid';
document.getElementById('UserEmail').style.borderWidth='2px';
document.getElementById("formErrors").innerHTML = "The Email Address: <?php echo $UserEmail ?> has already been used, Please Use a Different Email Address.";
}
</script>
表单字段中的问题:(表工作正常)
<div>
<label for="email">Email</label>
<input type="email" id="UserEmail" name="email">
</div>
是那个php?您需要将相关标签添加到您的问题 – Liam
**危险**:您正在使用[一个**过时的**数据库API](http://stackoverflow.com/q/12859942/19068),并应使用[现代替代品](http://php.net/manual/en/mysqlinfo.api.choosing.php)。你很容易受到[SQL注入攻击](http://bobby-tables.com/)**现代的API会使它更容易[防御](http://stackoverflow.com/questions/60174/最好的方式,以防止SQL注入在PHP)自己从。 – Quentin
我可以考虑一些可能的原因,为什么这可能会失败,但代码没有足够的上下文来告诉它们可能是哪一个。他们中的大多数会给出一些非常明显的错误消息。浏览器的开发工具中的控制台说什么? – Quentin