I have jquery-ui dialog has some inputs fields for update user information.
whenever the user type into one of these fields (using keyup()
), the value of the input will be sent to database to check weather that name exist in the data base or not. Unfortunatelly, it always return that there is no such a name in database (even if it actually exist).
Notice: the form of "update user information" is included to index.php
(main page). I tried to make a new project with that form as main page, and it works properly. So I'm thinking there is problem with including the form page in its main page. Is that right?!!
the form that included to main page:
<div id="container">
<form action="" class="fixed-dialog" id="customForm" dir="ltr">
<table>
<tr>
<td id="label-td"><label for="name">firstName</label></td>
<td id="input-td">
<input type="text" class="form-group" id="firstName" name="name" />
</td>
<td id="span-td">
<span id="firstNameInfo">first Name</span>
</td>
</tr>
</table>
<div>
<input type="button" name="send" id="send" value="Update">
</div>
</form>
</div>
Javascript file: that includes jquery-ui dialog and validating the input field:
var form = $("#customForm");
var name = $("#firstName");
var nameInfo = $("#firstNameInfo");
var state = false;
name.keyup(validateName);
function validateName(){
if(name.val().length < 2){
name.removeClass("valid");
nameInfo.removeClass("valid");
name.addClass("error");
nameInfo.addClass("error");
nameInfo.text("More than Two Letters!!");
state = false;
}else{
if(name.val().length >= 2){
var username = name.val();
//here, getting validate.php page, which takes the value of the input and check it with DB
$.post('includes/validate.php',{names:username}, function(data){
if(data != 0){
//if there is a match with DB.
name.removeClass("valid");
nameInfo.removeClass("valid");
name.addClass("error");
nameInfo.addClass("error");
nameInfo.text("it's already there..");
state = false;
}else{
//if there is no match with DB.
name.removeClass("error");
nameInfo.removeClass("error");
name.addClass("valid");
nameInfo.addClass("valid");
nameInfo.text("Accepted!!");
state = true;
}
});
}
}
return state;
}
the last file is validate.php, which will check for the input value in the DB:
include "includes/config.php";
include "./functions.php";
$name = &$_POST['names'];
if($name != ""){
arabicQuerySetUp();
$query_search_name = "SELECT * FROM users WHERE user_first_name = '{$name}' ";
$query_search_name_result = mysqli_query($dbc, $query_search_name);
$count_names = mysqli_num_rows($query_search_name_result);
if($count_names != 0){
echo 1;
}else{
echo 0;
}
}
As I mentioned above, I tried to make it in new project, and not included it to the main page; and it's worked fine.
I tried too much to find where the error is in my code, but I couldn't. So I came here looking for any help.
Thanks in advance.