I’m trying to submit a form and process it with php. Here’s what I do (it simplified but still not working…)
here my index :
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script type="text/javascript" src="jquery-1.7.1.min.js"></script>
<script>
$().ready(function(){
$("#addemail").click(function(){
var email=$("#email").val();
$.ajax({
type: "POST",
url: "addemail.php",
data: "email="+email,
success: function(){
console.log("success! ")
},
error: console.log("error!! ")
});
});
});
</script>
</head>
<body>
<div id="wrapper">
<h2>Mon form...</h2>
<form action="">
<table>
<tr><td><label>Email:</label></td>
<td><input type="text" id="email" name="email" /></td>
<td><input type="submit" id="addemail" value="Add" /></td>
</tr>
</table>
</form>
</div>
</body>
Here’s my php file:
<?php
$connection = mysql_connect('localhost', 'XXX', 'XXX');
$db= mysql_select_db('mydb', $connection);
$email= $_REQUEST["email"];
$query = "INSERT INTO users(email) VALUES ('$email')";
mysql_query($query);
?>
What Am I doing wrong (probably not the php because if i give it to action in my form it s working but in php not ajax…)
Thanx in advance
SQL Injection Vulnerability!
Also, wouldn’t you need to add semicolons?
And put the error inside an anonymous function?
Also your form should be as complete as possible: