I have this database :
Table User : username, password
Table Product : productID, productName
In my admin.php, if I click button with id btn, I want to display insert.php in a div with id show
admin.php :
<?php
session_start();
include("connection.php");
?>
<html>
<head>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("#btnInsert").click(function(){
$("#show").load("insert.php");
});
$("#btnEdit").click(function(){
$("#show").load("edit.php");
});
$("#btnAdd").click(function(){
$("#show").load("insertbrg.php");
});
});
</script>
</head>
<body>
<div id = "menu">
<button id = "btn">Insert</button><BR>
</div>
<div id = "show">
</div>
</body>
</html>
And in insert.php :
<?php
session_start();
include("connection.php");
?>
Product ID : <input type = "text" name = "txtID"><BR>
Product Name : <input type = "text" name = "txtName"><BR>
<input type = "button" name = "btnAdd" id = "btnAdd" value = "Add Item to DB">
if I click btnAdd, the jquery in admin.php will load insertbrg.php to add Item to database
insertbrg.php :
<?php
if(isset($_REQUEST['btnAdd'])){
$newID= $_REQUEST['txtID'];
$newName= $_REQUEST['txtName'];
$query = "Select * from Product";
$result = mysql_query($query,$conn);
$idExist = false;
if($result){
while ($row= mysql_fetch_array($result))
{
if ($row["productID"] == $newID){
$idExist = true;
}
}
}
if ($idExist){
echo "ID Exist ";
}else{
$query2="insert into product values('$newID','$newName')";
$result = mysql_query($query2,$conn);
header("location:insert.php");
}
}
?>
I can't insert the item to my db if I clicked the btnAdd button
And also I get this warning :
event.returnValue is deprecated. Please use the standard event.preventDefault() instead.
everytime I click the btn button in admin.php
Anyone know what's wrong? I'm a newbie in JQuery AJAX. Please Help...
event.returnValue is deprecated.is a notice that is coming (probably) from an old version of jQuery or other included javascript files. You'll need to upgrade, or replace withevent.preventDefault. I'm sure there are plenty of questions on SO about it..load("insertbrg.php"). What do you expect it to add?header("location:")in an AJAX server function? The whole point of using AJAX is that the page is not reloaded.