SELECT statement after UPDATE calls old data
Posted: Fri Nov 26, 2010 4:59 am
I have a PHP page which updates a database record and immediately after selects the data again for display on the page. The problem I am having is the SELECT statement loads the OLD data, regardless of the fact that the select statement appears after the update query. However, looking at the data in the database the information has been updated correctly, so if I then refresh the page sure enough it shows the correct data.
Many thanks in advance,
Chris
EDIT:
Oh and a couple of things I've done to debug, I've tried:
- Putting in a sleep command in between the two queries
- Running an SQL FLUSH CACHE statement
- Closing the database connection and opening it again
None of these seem to work.
Code: Select all
$songId = $id[0];
$updateQry = mysql_query("UPDATE hits SET song = '".$titles[0]."', artist = '".$artists[0]."', year = ".$years[0].", chart = ".$charts[0].", month = '".$months[0]."', quantity = ".$quantity[0]." WHERE ID = ".$songId) or die(mysql_error());
$selectQry = mysql_query("SELECT * FROM hits WHERE id = ".$songId);
while($row = mysql_fetch_array($result))
{
echo "<strong>New Data:</strong><br/>";
echo "ID: " . $row["ID"] . "<br/>";
echo "Title: " . $row["song"] . "<br/>";
echo "Artist: " . $row["artist"] . "<br/>";
echo "Year: " . $row["year"] . "<br/>";
echo "Chart: " . $row["chart"] . "<br/>";
echo "Month: " . $row["month"] . "<br/>";
echo "Quantity: " . $row["quantity"] . "<br/>";
}Chris
EDIT:
Oh and a couple of things I've done to debug, I've tried:
- Putting in a sleep command in between the two queries
- Running an SQL FLUSH CACHE statement
- Closing the database connection and opening it again
None of these seem to work.