I've just got a question about updating PHP sessions without reloading or redirecting to a separate page. For instance, say you have a catalogue of car models that you wanted to pick and choose your favorites from. While searching through the online catalog, you find a car that you're interested in. With the script that I'm looking for, you would be able to simply click "Add to Favorites" or something and it would automatically save it to a session variable favorites and then you could go to a separate "favorites" page that lists all the car models that you chose as your favorite. When you add a car to your favorites, the link that you'd press would just change automatically to "Remove from Favorites" or something without having to reload the page. Does that kind of make sense? I don't have any code snippet to show since I'm basically just looking for how to do it in the first place. I assume it'd be Javascript that I'd need to use in order to change the variable seeing as how PHP only runs once when a page is loaded. Unless I'm mistaken.
You could use AJAX (javascript) like on iStockPhoto when you add something to your lightbox (favorites). It pops over the page and runs a request to the backend servers without reloading where you are. You could also do it the old fashioned way with a tiny invisible iframe. Javascript sends an src='' command to the iframe, which loads a php page adding the necessary db rows.
Here's how I do pretty much the exact same: The list of items I display has some JavaScript links. onClick an AJAX event happens. It executes a file like favourites.php?session_id=kj67986dsv76sdv&ip=123.456.789 The php file stores the favourites list in MySQL and references, without the user having to log in or anything liek that, by IP and session_id. No iFrames, no direct writing to session vars (which you could do - just open the session file in tmp directly and write to it).
What would that javascript/AJAX code look like for the onclick event? And maybe how it would look if there were an iframe as well. Just so I can get some ideas.
http://www.google.co.uk/search?hl=en&q=ajax+shopping+cart+tutorial&btnG=Search&meta= those are what I used for inspiration.
Ah, I think I found kind of an example: http://www.rapha.cc/index.php?page=24 Where it says "Buy Online" on the mid right-hand side, select something then click "Add." It automatically adds it without reloading. EDIT: What exactly would I be looking for under those results, T0PS30?
I've decided to go with the iFrame method instead of AJAX (I'm not familiar with AJAX whatsoever and I couldn't exactly find what I was looking for in the way of tutorials, unless someone can point me to some good AJAX tutorials) I'm just bumping this to ask: How would I go about using an iFrame to do this? Or AJAX? What would the code look like?
Here is a useful link for AJAX. It really is a 30 second AJAX tutorial. Cheers, http://blog.coderlab.us/rasmus-30-second-ajax-tutorial/
With an iFrame, all you need to do is setup a small/invisible iFrame somewhere on the page. 1 x 1 pixels in size and then set the CSS display to none. Now within that iFrame, you load your database controls. Whenever the user clicks a certain button, you change the SRC in the iFrame so that it loads a script on the server updating the database.
Ah ok. Right on. Thanks! I'm also going to keep looking into doing it the AJAX way, simply for some useful extra knowledge. Thanks TheHoff and azizny.