I have this code in JavaScript and jQuery and I need to fix it:
function valid_form() {
val_avail_email=valid_avail_email();
if (val_avail_email!="") {
$("#email_valid").html(val_avail_email);
return false;
}
return true;
}
function valid_avail_email() {
var error="";
$.get("valid_avail_email.php",{email:document.reg_form.email_reg.value},function(output) {
error=output;
});
return error;
}
So obviously I want the error
variable to contain the output of the valid_avail_email.php
and than make the valid_avail_email()
function return that value.
Here is the code in valid_avail_email.php
:
<?php
include("config.php");
$email=$_GET["email"];
$sql="select email from users";
$sql_query=mysql_query($sql);
if (!$sql_query) {
echo mysql_error();
}
$res_assoc = mysql_fetch_assoc($sql_query);
foreach ($res_assoc as $field=>$value) {
if ($value==$email) {
echo "please use another email this one is taken ";
}
}
?>