Jump to content

Recommended Posts

Hello all,

I have put together a simple php site that uses a mysql database to record game and player records

Whenever 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!

Link to comment
https://forums.phpfreaks.com/topic/286328-displaying-invalid-results-set/
Share on other sites

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.

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.

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 => Host
Cache-Control => no-cache, no-store, must-revalidate
Pragma => no-cache
Expires => 0
Content-Type => text/html
Content-Length => 33665
Date => Thu, 20 Feb 2014 02:52:13 GMT

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.