Hi I'm new to PHP and jQuery and I was doing some tests trying to figure out how things work. But I keep having trouble transferring data back and forth between my web page and the php file on the server. Here is the code:
<center>
<form>
<hr>
<table style="width:80%;border:3px;">
<tr>
<td align="center"><input type="text" id="name" placeholder="First Last"></td>
<td align="center"><input type="text" id="ssn" placeholder="First Last"></td>
<td align="center"><input type="text" id="birth" placeholder="First Last"></td>
<td align="center"><input type="text" id="xxxx" placeholder="First Last"></td>
<td align="center"><button type="button" id="add">Add</button></td>
<script>
$("#add").click(function() {
var nameIn = $('#name').val();
var ssnIn = $('#ssn').val();
var birthIn = $('#birth').val();
var xxxxIn = $('#xxxx').val();
xxxxIn = "\$" + xxxxIn;
$.ajax({
type:"POST",
url:"database_update.php",
dataType:"JSON",
data: {
name: nameIn,
ssn: ssnIn,
birth: birthIn,
xxxx: xxxxIn
},
success: function(ret) {
var out = JSON.stringify(ret);
alert(out);
}
});
});
</script>
</tr>
</table>
</form>
</center>
<?php
$name = $_POST['name'];
$ssn = $_POST['ssn'];
$birth = $_POST['birth'];
$xxxx = $_POST['xxxx'];
header('Content-type: application/json');
if (isset($name))
{
$ret = array(
"name" => $name,
"ssn" => $ssn,
"birth" => $birth,
"xxxx" => $xxxx
);
echo json_encode($ret);
} ?>
The alert function was never triggered and the response from php was successful.