Please find my code below...This is basically 2 files javascript and php file.
I am trying to call the php file from the javascript. But I get a 500 internal server error when the jquery function is called.
When I checked chrome web developer tools, I can see that the execution is stopping in one of the jquery library functions. But I could be wrong in that judgement since I am not totally familiar with developer tools.
Could you please let me know whats going wrong?
validation.js
function validateName(){
var uname=name.val();
$.post('validate.php',{names:uname},function(data){
if(data!=0){
name.removeClass("valid");
nameInfo.removeClass("valid");
name.addClass("error");
nameInfo.addClass("error");
nameInfo.text("This name is already registered");
state=true;
}else
{
name.removeClass("error");
nameInfo.removeClass("error");
name.addClass("valid");
nameInfo.addClass("valid");
nameInfo.text("Name is available");
state=true;
}
});
return state;
}
$( "#send" ).click(function() {
var all = $("form").serialize();
$.ajax({
url: 'insert.php',
type:'POST',
data: all,
dataType: "text",
success: function (response) {
if (response==1){
document.location.href="/view.html";
}else{
alert("you have errors");
}
}
});
insert.php
<?php
$name=$_POST['name'];
$email=$_POST['email'];
$pass=$_POST['pass1'];
mysql_connect("localhost","root","root") or die("we couldnt connect");
mysql_select_db("swiftyfood");
mysql_query("INSERT INTO userCredentials(userid,name,password) VALUES('',
'$name','$pass1')");
echo 1;
?>
Validate.php
<?php
echo "hello";
ini_set('display_errors', 1);
error_reporting(E_ALL);
$name=$_POST['names'];
$email=$_POST['emails'];
$pass=$_POST['passws'];
if ($name!=""){
mysql_connect('localhost','root','root') or die("we couldnt connect");
mysql_select_db("swiftyfood");
$username=mysql_query("select name from userCredentials where
name='$name'");
$count=mysql_num_rows($username);
if (count!=0){
echo 0;
}else{
echo 1;
}
?>
image of chrome developer tools.