Reputation: 139
My webpage has a table where you can select different items. I want to be able to let people rate these. I ran into a problem where I would need to pass a javascript variable to php, and from what I read online isn't the easiest thing. How would you suggest I do this?
The code is stored at 98.214.131.200/index.php and 98.214.131.200/ratings/ratings.php
currently I have functions in ratings.php that allow me to write or read the ratings, but I need the a string from the javascript to identify which item is being rated.
Upvotes: 0
Views: 258
Reputation: 5386
You can use jquery, and pass the information behind the scenes. Something like this:
$.ajax({
type: 'POST',
url: "/your/processing/url/here.php",
data: {rating_id: item_id, rating: 4}, // <-- set this dynamically with your item
success: function()
{
// do something - success
},
dataType: dataType
});
Upvotes: 1
Reputation:
You could pass the rating using a POST request from a form.
http://www.tizag.com/phpT/forms.php/
Make sure you correctly sanitize your inputs to avoid SQL injections
http://www.tizag.com/mysqlTutorial/mysql-php-sql-injection.php
Upvotes: 1
Reputation: 1641
You can try passing the rating as a GET
variable in the URL directly. That way you can do ./ratings.php?rating=5&item=20, and get those values in PHP as $_GET['rating']
and $_GET['item']
.
Upvotes: 0