index.html:
<!DOCTYPE html>
<html lang="en">
<head>
<body>
<form id="myform" action="userinfo.php" method="post" >
Name: <input type="test" name="name" autofocus>
Age: <input type="text" name="age" >
<button id="sub"> save</button>
</form>
<span id="result"></span>
<script src="script/jquery-1.8.1.min.js" type="text/javascript"></script>
<script src="script/my_script.js" type="text/javascript"></script>
</body>
</html>
my_script.js:
$("#sub").click( function() {
$.post( $("#myform").attr("action"),
$("#myform :input").serializeArray(),
function(info){ $("#result").html(info);
});
clearInput();
});
$("#myform").submit( function() {
return false;
});
function clearInput() {
$("#myform :input").each( function() {
$(this).val('');
});
db.php:
<?php
$conn = mysql_connect('localhost','B00556019','73eKESV3') ;
$db = mysql_select_db('b00556019');
?>
userinfo.php:
<?php
include_once('db.php');
$name = $_POST['name'];
$age = $_POST['age'];
if(mysql_query("INSERT INTO user (name, age) VALUES (
'$name','$age')";))
echo "Successful";
else
echo "insertion failed";
?>
It won't post to database
database name: b00556019
table: user
fields: name(varchar, 15). age(INT, 3)
nothing happens apart form the userinfo page is displayed as blank.
Anybody with some advice in how to post to the database would be great and also if someone has an easy tutorial as this was a basic tutorial but still didn't work.