Just got an error after fixing my code, please consider that the userID in the database is all set to '0'!
Outprint:
userID: '23' itemID: '8204'
UPDATE booking SET userID ='23' WHERE itemID ='8204'
(Error:) Could not update data: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '1' at line 1
UPDATED PHP code second time:
<?php
$con = mysql_connect("localhost", "root", "") OR die(' Could not connect');
$db = mysql_select_db('book1', $con);
if (isset($_GET["userID"]) && isset($_GET["itemID"])){
$userID= (int)$_GET["userID"];
$itemID= (int)$_GET["itemID"];
$test = "userID: '$userID' itemID: '$itemID'";
echo $test;
echo "<br>";
}
if (!$con) {
die('Could not connect: '.mysql_error());
}
echo("UPDATE booking SET userID ='$userID' WHERE itemID ='$itemID'");
echo "<br>";
$upd = mysql_query("UPDATE booking SET userID ='$userID' WHERE itemID ='$itemID'");
$retval = mysql_query($upd, $con);
if(!$retval){
die('Could not update data: '.mysql_error());
}
echo "Updated data successfully\n";
$sql = mysql_query("SELECT * FROM booking");
if($sql === FALSE) {
die(mysql_error());
}
echo '<table class="fixed">
<tr>
<th>itemID</th>
<th>EMPLOYEE ID</th>
</tr>';
while($row = mysql_fetch_array($sql)) {
echo "<tr>";
echo"<td>".$row['itemID']."</td>";
echo"<td>".$row['userID']."</td>";
echo "</tr>";
}
?>