I'm going crazy! I'm trying to submit a form from jquery to php and insert a record in my database. I'm getting no error, but no record is being submitted. All works fine when I just go to the php page and put variables in the URL. But it doesn't work when I submit the variables via the jquery page. Can anyone help me out, please?
HTML:
<form id="tellusForm" >
<div class="formHead">Tell us your story</div>
<div id="thank">Thank you.</div>
<table cellpadding="5">
<tr><td>Name:</td><td><input id="tellName" type="text"/></td></tr>
<tr><td>Country of origin:</td><td><select id="tellCountry"></select></td></tr>
<tr><td>Age:</td><td><input type="text" id="tellAge"/></td></tr>
<tr><td>Occupation:</td><td><input type="text" id="tellOccupation"/></td></tr>
<tr><td>Email address:</td><td><input type="text" id="tellEmail"/></td></tr>
<tr><td>Phone number:</td><td><input type="text" id="tellPhone"/></td></tr>
<tr><td>A bit about you:</td><td><textarea id="tellAbout" style="width: 100%;"></textarea></td></tr>
<tr><td></td><td><input type="submit" value="Send" class="submit"/></td></tr>
</table>
</form>
jquery:
$('.submit').click(function(){
$.get('tellus.php', { name: "laura"}, function(data){
eval(data);
});
});
tellus.php:
<?php
require_once ('../constants_test.php');
$name = $_GET['name'];
$db = new mysqli(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
if (mysqli_connect_errno()) {
printf("Connect failed: %s", mysqli_connect_error());
exit;
}
$q = "Insert into tellus(`Name`) values ('" . $name . "')";
if ($db->query($q)) {
echo "console.log('you got it')";
};
$db->close();
?>