I am really in doubt how to get started on this code. In my DIV tag "talraekke" I want to receive the last 10 records from my database. That means everytime I put in a number in my form field, the div tag should be updated with the latest number, without I have to update the page. Could anybody help me on the way?
Best Regards Julie
PS: Please look away from the outdated php/sql statements :-) This is just a test session for me.
HTML
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="js/my_script.js" type="text/javascript"></script>
<link rel="stylesheet" type="text/css" href="css\placing.css">
<title>Numbers</title>
</head>
<body>
<div class="topbar">
<p>Topbar</p>
</div>
<div class="talraekke">
****Recieve from DB******
</div>
<div class="content">
<p>Enter The Number</p>
<form id="myForm" action="userInfo.php" method="post">
<input type="value" name="numbervalue">
<button id="sub">Save</button>
</form>
<span id="result"></span>
</div>
</body>
</html>
JS:
// Insert function for number
function clearInput() {
$("#myForm :input").each( function() {
$(this).val('');
});
}
$(document).ready(function(){
$("#sub").click( function(e) { // note the 'e'
e.preventDefault(); // remove default action(submitting the form)
$.post( $("#myForm").attr("action"),
$("#myForm :input").serializeArray(),
function(info){ $("#result").html(info);
});
clearInput();
});
})
// Receive data from database
PHP:
<?php
include('connection.php');
// Insert To Database
$strSQL = "INSERT INTO numbertable(numbers) VALUES('" . $_POST["numbervalue"] . "')";
if(mysql_query("INSERT INTO numbertable VALUES('numbers')"))
echo "Insert Succesfull";
else
echo "Failed";
// The SQL statement is executed
mysql_query($strSQL) or die (mysql_error());
// Close the database connection
mysql_close();
?>