kkita727 Posted February 19, 2014 Share Posted February 19, 2014 Hello all, I have put together a simple php site that uses a mysql database to record game and player recordsWhenever I attempt to update or insert a record, the database does reflect the change, however when I attempt to run the select query a second time, it returns a result set as if the update or insert never took place. The updates and inserts are permanent so it doesn't seem like a rollback issue.When I clear the web browser's cache and cookies and reload the page, the select statement does return the updated records, so are there perhaps any caching issues that I might need to look into?Upon page load, selectplayers is called and will return player A and B. I then call deleteplayer to remove B and the record is indeed removed from the database. I call selectplayers a second time and it still returns player A and B. If I clear the cache and reload the page, it returns only player A.function selectplayers() { $db = new db("mysql-t","user","password","database"); $id = $db->escape($_REQUEST["id"]); $db->execute("SELECT name FROM players WHERE id=$id"); $db->close(); //echo result set to page}function deleteplayer() { $db = new db("mysql-t","user","password","database"); $id = $db->escape($_REQUEST["id"]); $db->execute("DELETE FROM players WHERE id=$id"); $db->close();} My php knowledge is pretty limited, so any suggestions would certainly be appreciated. Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/286328-displaying-invalid-results-set/ Share on other sites More sharing options...
requinix Posted February 19, 2014 Share Posted February 19, 2014 Are you sure you didn't do the SELECT before making the changes? Also, $db->execute("DELETE FROM players WHERE id=$id"); Try to avoid deleting data whenever you can. It'll help you in the long term when you're able to look at data and not have holes because you permanently deleted something that was useful to know.Mark the player as "deleted", then modify your selectplayers() and other similar functions to not return players that have been marked as such. Quote Link to comment https://forums.phpfreaks.com/topic/286328-displaying-invalid-results-set/#findComment-1469578 Share on other sites More sharing options...
kkita727 Posted February 19, 2014 Author Share Posted February 19, 2014 Yes, the select and the delete functions are triggered by two different buttons at the moment, so I'm sure the delete occurs first. Thanks for the suggestion about deleting records. Quote Link to comment https://forums.phpfreaks.com/topic/286328-displaying-invalid-results-set/#findComment-1469579 Share on other sites More sharing options...
requinix Posted February 19, 2014 Share Posted February 19, 2014 Then it could very well be caching. Likely by the browser, which means your site is sending some sort of response headers telling the browser to do caching. Can you see what the headers are? (If you're not sure how, no offense but it'll be easier for everyone if you Google it.) Relevant headers include Cache-Control, Pragma, Expires, and Last-Modified, and while you're there try to see if your browser sends headers such as If-Modified-Since or If-None-Match. Quote Link to comment https://forums.phpfreaks.com/topic/286328-displaying-invalid-results-set/#findComment-1469580 Share on other sites More sharing options...
kkita727 Posted February 20, 2014 Author Share Posted February 20, 2014 Origionally, it was set to cache, but even after modifying the headers I'm still having the same issue Server => Apache/2.2.15 (CentOS)Vary => HostCache-Control => no-cache, no-store, must-revalidatePragma => no-cacheExpires => 0Content-Type => text/htmlContent-Length => 33665Date => Thu, 20 Feb 2014 02:52:13 GMT Quote Link to comment https://forums.phpfreaks.com/topic/286328-displaying-invalid-results-set/#findComment-1469597 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.