i am trying to update my records using UPDATE in php and mysql , the query working but there is not updates at all happened on the database , i have many records for tickets which i need to update there status when the user purchase them , let say the user books 10 tickets i used this syntax
for ($counter = 1; $counter <= $tickets; $counter++) {
echo $eventId;
echo $chooseClass;
echo $chooseUser;
$bookTicket = mysql_query("UPDATE units
SET ticketSold = 'Yes',
userIdFK = '$chooseUser'
WHERE BusinessreservationIdFk = '$eventId'
AND classIDfk ='$choosedClass'"
) or die(mysql_error());
if ($bookTicket)
{
echo "<br/>ticket " . $counter . " done !";
}
else
{
i tried to echo all variables here inside the for loop to make sure this for gets all the variables values , which is working , i have like 1000 tickets already stored on mysql table units which i need to update their status from sold = No to Yes. where is the problem here ?
try building the query separately (e.g.
$sql = 'UPDATE ...', so you can do anecho $sqland copy/paste the query and run it manually. Nothing in your code looks wrong, so the values you’re passing around must not be correct or theWHERE ...logic isn’t proper. So run a sample query manually and see if anything happens then.However, note that you’re doing this inside a
for()loop, but aren’t using that $counter value anywhere. In effect you’re just running the SAME query over and over. SettingticketSoldtoYes$counter times isn’t going to make it “more”Yesthan if you’d done this update only once.