Code: Select all
<form method="POST" action="pratingsystem.php">
<?php
echo '<input type="hidden" name="jokeId" value="$id">'; //$id comes from what's earlier on the page, a dispay script
?>
<input type="radio" value="5" checked name="rating">Excellent
<input type="radio" name="rating" value="4">Good
<input type="radio" name="rating" value="3">OK
<input type="radio" name="rating" value="2">Not-so-good
<input type="radio" name="rating" value="1">Sucks</p>
<p><input type="submit" value="Submit" name="B1"></p>
</form>Code: Select all
<?php
if ($rating==""){
echo "Go back and select a rating";
}
else
{
$db="mysql_connect('localhost', '', '')"
mysql_select_db(db_thawowi_2, $db)"
$number=0;
$number="SELECT number FROM table WHERE id='$jokeId'"; //I need the id part
$number=$number+1;
$query="UPDATE table SET number='$number' WHERE id='$jokeId'";
$result="mysql_query($query, $db); inserted the new total
$total=0;
$total="SELECT total FROM table WHERE id='$jokeID'";
$total='$total'+'$rating';
$secondquery="UPDATE table SET total='$total' WHERE id='$jokeID'";
$secondresult="mysql_query($secondquery, $db);
$average="$total/$number";
/*total is the number I get after adding all user submissions together,
this is (if I remeber math correctly) the formula for finding the arithmetic
mean */
$finalquery="UPDATE table SET average='$average'";
$finalresult="mysql_query($finalquery, $db)";
echo "some success message";
}
?>My question is, will all this work in order? (update $number first, $total second, and $average third). If not, is there a way to make without writing 3 separate codes?
As of right now, this does not work. It gives me the success message, but when I go into my database, I see no changes. Why is this?
Please check for parse errors, this could be a stupid parse error. I probably messed up in single quotes, double quotes, no quotes, etc. Under which circumstances are each of these quotes used?
Thanks.