Forum Moderators: coopster
So variable 'arating' is the avaerage rating, which I then display on the product page.
Now I need the customer to be able to add their vote to the rating system. Here is what I do:
echo"Rating: $arating<br><form action='http://www.examplesite.com/business.php' method='post'>
<select name='ud_urate'>
<option value='1'>1</option>
<option value='2'>2</option>
<option value='3'>3</option>
<option value='4'>4</option>
<option value='5'>5</option>
</select><input type=submit value='Submit'>
</select>";
Okay that is the form. Now it is supposed to take their entered value and add it to the old rating.
$ud_rate=$rating+ud_rate;
Then send the new information back to the database, and then when the page is reloaded the database is updated.
$query = "UPDATE business SET rating = '$ud_urate' WHERE id = '$page_num'";
mysql_query($query);
Unfortunatley, this does not update the database. It just remains the same.
FYI: $page_num is determined earlier on by a query string in the URL and helps to determine what the starting product in the list is.
Thanks for any help.
The problem is that I need the part that updates the database only to happen when the form is submitted. Now I thought of just making a new php file and executing it from there (form action='newpage.php'). However, the problem is that this is the scripting for 1 of 9 products on the page. So, the new page wont be able to tell which product is being rated. How can I transfer the value of one variable on the original page to a new page? Or is there another way to do this?
The problem is that I need the part that updates the database only to happen when the form is submitted. Now I thought of just making a new php file and executing it from there (form action='newpage.php'). However, the problem is that this is the scripting for 1 of 9 products on the page. So, the new page wont be able to tell which product is being rated. How can I transfer the value of one variable on the original page to a new page? Or is there another way to do this?
simple!
when you make form like
echo "<form action=newpage.php>";
make a hidden field in that form containing the id of the product for which rating is being made like
echo "<form action=newpage.php>";
echo "<input type=hidden name=productid value='$id'>";
take product id from mysql and put it over there, so when newpage.php gets called it can update rating for that very product.
this was just to answer that question, the above two suggestions by those senior guys are much more recommended.