Jump to content

ONE MORE ajax problem


Alfraganus

Recommended Posts

i dont know why but, ajax is not sending request to database, I supposed to register email with the help of database, let me show codes,

 

when I am clicking submit button, nothing is happening.

 

HTML----

<html>
<head>
<script>
$(document).ready(function(){
$("#sub").click(function(){
var name = $("#name").val();
var email = $("#email").val();
var pass = $("#pass").val();
$.POST('test.php',{
name:name,email:email,pass:pass
},function(data){
$("#result").html(data);
});
});
});
</script>
</head>
<body>
<div id="box">
<h2>new user register</h2>
<input type="text" name="name" id="name" placeholder="enter your name"/><br>
<input type="text" name="email" id="email" placeholder="enter your email"/><br>
<input type="password" name="pass" id="pass"/><br>
<input type="submit" name="sub" value="submit" id="sub" >
<div id="result"> </div>
</div>
</body>
</html>
----test.php............
<?php
$con=mysqli_connect("localhost","root","","test");
$name=$_POST ['name'];
$email=$_POST ['email'];
$pass=$_POST ['pass'];
$sel="select * from users where email='$email'";
$run=mysqli_query ($con, $sel);
$check_email=mysqli_num_rows ($run);
if ($check_email==1) {
echo "<h2>This is email is already registered, try another</h2>";
exit();
} else {
$insert="insert into users (name,pass,email) values ('$name','$pass',$email')";
$run_insert=mysqli_query($con,$insert);
if($run_insert) {
echo "<h2>registration has been succesfull G'ulomjon aka </h2>";
}
}
?>

 

Link to comment
Share on other sites

Press F12 to open the Javascript console, then click the button and see what shows up there.

 

Your code will fail if somebody types ' OR 1 OR ' as their e-mail address. You should research SQL injection.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...