Hi all. I am trying to pass values from a form through a “url query string” to update.php (using Ajax). ‘update.php’ retrieves the string and copies it to a database. Should I be using Get or Post for this?
I have created some code that sends the query string, but it will not post to the database. Can someone run through this simple code real quick and help me find the (probably) simple solution?
example.html:
[CODE]<html>
<head>
<script type=”text/javascript”>
function showCustomer()
{
var xmlhttp;
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject(“Microsoft.XMLHTTP”);
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById(“txtHint”).innerHTML=xmlhttp.responseText;
}
}
var match = document.getElementById(‘match’).value;
var score = document.getElementById(‘score’).value;
var queryString = “?match=” + match + “&score=” + score;
xmlhttp.open(“GET”, “update.php” + queryString,true);
xmlhttp.send();
}
</script>
</head>
<body>
<form action=””>
<select name=”match” id=”match”>
<option value=”Eng1 ChelseaLiverpool”>Chelsea – Liverpool</option>
<option value=”EngFACup ArsenalWigan”>Arsenal – Wigan</option>
<option value=”Eng2 WatBromley”>Watford – Bromley</option>
<option value=”Sing1 SAFGombak”>SAF – Gombak United</option>
</select>
<select name=”score” id=”score”>
<option value=”00″>0-0</option>
<option value=”10″>1-0</option>
<option value=”01″>0-1</option>
<option value=”11″>1-1</option>
</select>
<input type=”submit” onclick=”showCustomer()” value=”Submit Pick” />
</body>
</html>
update.php:
[CODE]<?php
$match = $_GET[‘match’];
$score = $_GET[‘score’];
mysql_connect (‘localhost’, ‘admin’, ‘password’) or die (‘Error: ‘ .mysql_error());
mysql_select_db (“example_db”);
$query=”INSERT INTO user (FirstName, Lastname)VALUES (‘”.$match.”‘, ‘”.$score.”‘)”;
mysql_query($query) or die (‘Error submitting’);
?>