First of all I like to say that I'm super bad at this type of stuff so my code can be totally useless.
The mission is to create a system that will ask the user to scan two ID's, userID and itemID. After the scan has been successful I want these values to be transported to a PHP document. Here I'd like to run a MySQL query which will update the value of userID where itemID match the database.
So my problem is that I get this message after running my query: userID:202 itemID:8204 Could not update data: Query was empty. And ofc my database remains empty.
I think the problem is that the query can't read the $_GET variables. But I have no clue so please help me, Thanks!
This is my form:
<form id="checkin" name="checkin" action="test.php">
<input type="button" onclick="checkIn()" value="Check in Item">
</form>
The function:
<script>
function checkIn(){
var userID=parseInt(prompt ("Scan userid"), 10);
var itemID=parseInt(prompt ("Scan itemid"), 10);
if(userID!=null && itemID!=null){
window.location.href= "http://localhost/webapp/test.php?userID=" + userID + "&itemID=" + itemID;
alert ("working so far userID:"+ userID + " --- itemID:" + itemID);
}
}
</script>
At last the PHP:
$con = mysql_connect("localhost", "root", "", "book1");
$db = mysql_select_db('book1');
if (isset($_GET["userID"]) && isset($_GET["itemID"])) {
$userID1 = (int)$_GET["userID"];
$itemID2 = (int)$_GET["itemID"];
$test = "userID: ".$_GET["userID"]." "."itemID: ".$_GET["itemID"];
echo $test;
}
if (!$con) {
die('Could not connect: '.mysql_error());
}
$upd = mysql_query('UPDATE INTO booking SET userID ="$userID" WHERE ID ="$itemID');
$retval = mysql_query($upd, $con);
if (!$retval) {
die('Could not update data: '.mysql_error());
}
echo "Updated data successfully\n";