Why this code is not working.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<script language="javascript">
var http="";
if(navigator.appName == "Microsoft Internet Explorer"){
http = new ActiveXObject("Microsoft.XMLHTTP");
}
else{
http = new XMLHttpRequest();
}
function insert(){
document.getElementById('error').innerHTML = "Please wait a second";
var tp = document.getElementById('type').value;
var it = document.getElementById('item').value;
http.open('GET', '1.php?type='+tp+'&item='+it);
http.send = null;
if(http.readyState == 4){
document.getElementById('error').innerHTML = "Data Inserted";
}
}
</script>
<style type="text/css">
<!--
body,td,th {
font-family: Comic Sans MS;
}
-->
</style></head>
<body>
<form action="javascript:insert()" method="get">
<table width="422" cellspacing="3" cellpadding="3">
<tr>
<td width="66">Type</td>
<td width="333"><input name="type" type="text" id="type" /></td>
</tr>
<tr>
<td>Item</td>
<td><input name="item" type="text" id="item" /></td>
</tr>
<tr>
<td> </td>
<td><input type="submit" name="Submit" value="Insert" onclick="insertg();"/></td>
</tr>
</table>
</form>
<div id="error"></div>
</body>
</html>
And the 1.php
<?php
mysql_connect("localhost","name","password") or die(mysql_error());
mysql_select_db("database")or die(mysql_error());
$type = $_GET['type'];
$item = $_GET['item'];
if($type <> ""){
mysql_query("INSERT INTO likings (type, item) VALUES('$type', '$item')") or die(mysql_error());
}
?>