How to update database with server-side information without reloading the page

69
June 06, 2022, at 10:10 AM

I'm developing a like/dislike system using php and MySQL, but I have a problem. When I add a like, let's say, I do it by adding a row to the likes table, that contains the post id and the user id. The user id is stored in a $_SESSION, and I can't just pass it to the html and make a AJAX request to run some php code and add the like, because this way it's too easy to simply change the user id.

So basicaly I don't want to reload the page to first get the $_SESSION value but I don't now how to get it's value after the page has loaded. I don't know if this is doable with php only, if not, what language should I use

Answer 1

if you're using send ajax request for saving the like or dislike value. after saving the like/dislike value. you have to return a new like value count. in PHP simply echo the value that will automatically come to your ajax success if not simply return the new like/dislike info, encode with JSON and return the value. get these values in the success function and target the like and dislike button or div and change the new value with an ajax response.

if you want to code answer please share your code here so it's better understood by everyone

Rent Charter Buses Company
READ ALSO
Loop through associative array resulting from mysqli_fetch_assoc

Loop through associative array resulting from mysqli_fetch_assoc

I am new in the web development family and I really need help on that problemThe requirement is to get a list of video with their tags

67
"Update Cart" not triggering my woocommerce_after_cart_totals action hook

"Update Cart" not triggering my woocommerce_after_cart_totals action hook

I have a woocommerce_after_cart_totals hook action being done to output a specific JSON object to the cart pageIt works as expected on page load, however when someone changes qty and hits Update Cart button, the JSON variable disappears and a new one is not recreated

57
nginx cannot serve .php files from reverse proxy

nginx cannot serve .php files from reverse proxy

On reverse proxy machine (http://rp-server) the nginx configuration files is as follows:

57
Laravel Slug Exist

Laravel Slug Exist

I want to create slug for blog categoriesI do it like this;

108