As you can tell from the poor coding im not very experienced in PHP.
I changed the coding to:
foreach ($docrate_id as $id as $rating){
$update_table=sprintf("UPDATE doc_rate SET doc_rating = doc_rating + %s, num_of_votes = num_of_votes + 1 WHERE docrate_id = %s",
quote_smart($rating),
quote_smart($id))
when i try and run this i get invalid argument.
Sorry if i have not explained this well. Here is the whole thing incase it would be easier to see the whole page. And also if you have any time could to advise me on how i can improve PHP standards.
<?php
if (!isset($_REQUEST['submit'])){
$query = "SELECT * FROM doc_data, doc_rate WHERE doc_data.doc_id = doc_rate.doc_id ORDER BY doc_data.session, doc_data.idea, doc_data.doc_id";
$result = mysql_query($query) or die ("ERROR: Unable to Run $query".mysql_error());
?>
<form name=ratings method=REQUEST action=<?$_SERVER['PHP_SELF']?>>
<table border=0 cellpadding=3 cellspacing=3>
<tr>
<td><info>Please Enter Your Name: </info></td>
<td><input type=text name=name><required>*required</required></td>
</tr>
</table> <br />
<table border=1 cellpadding=3 cellspacing=3>
<tr>
<td><info>Session</info></td>
<td><info>Title of Brainstorm Idea</info></td>
<td><info>Inventor Name</info></td>
<td><info>Rating</info></td>
<td><info>Reset?</info></td>
</tr>
<?php
while ($row=mysql_fetch_assoc($result)){
echo "<tr>";
echo "<td><p align=center><data>".$row['session']."</center></data></td>";
echo "<td><data><a href=http://pws.stonehouse.oilfield.slb.com/SHTC/SER/IP-1/August_2006_Brainstorm/$row[url]>".$row['idea']."</a></data></td>";
echo "<td><data>".$row['inventor_name']."</data></td>";
if ($row['doc_rating'] < 1){
echo "<td><select name=".$row['docrate_id'].">
<option value=0 selected></option>\n
<option value=1>1 - Poor</option>\n
<option value=2>2 - Fair</option>\n
<option value=3>3 - Average</option>\n
<option value=4>4 - Good</option>\n
<option value=5>5 - Excellent</option>\n
</select>\n</td>";
} else {
echo "<td><p align=center><average>".$row['doc_rating']."</average></center></td>";
echo "<td><p align=center><input type=checkbox name=".$row['doc_id']." value=0></td>";
}
echo "</tr>\n";
}
echo "</table>\n";
echo "<br />";
echo "<input type=submit name=submit value=submit><br /><br />";
echo "</form>";
} else {
$query = "SELECT * FROM doc_data, doc_rate WHERE doc_data.doc_id = doc_rate.doc_id ORDER BY docrate_id";
$result = mysql_query($query) or die ("ERROR: Cannot Run Query".mysql_error());
?>
<br />
<?php
echo "$name,<br />";
echo "Your rating(s) have been recorded";
?>
<br />
<br />
<a href="http://localhost/rating/btable.php">View Table</a>
<br />
<br />
<a href="http://localhost/rating/brateDoc1.php">Back to Rating Form</a>
</div>
<?php
function quote_smart($value)
{
//STRIPSLASHES
if (get_magic_quotes_gpc()){
$value = stripslashes($value);
}
//QUOTE IF NOT INTEGER
if (!is_numeric($value)){
$value = "" . mysql_real_escape_string($value)."";
}
return $value;
}
foreach($docrate_id as $id => $rating){
if($doc_id && $docrate_id == 'submit'){
exit();
}
$update_table=sprintf("UPDATE doc_rate SET doc_rating = doc_rating + %s, num_of_votes = num_of_votes + 1 WHERE docrate_id = %s",
quote_smart($rating),
quote_smart($id));
$result = mysql_query($update_table) or die ("ERROR: Unable To Run $update_table".mysql_error());
}
foreach ($doc_id as $id => $reset){
$change_rating = sprintf("UPDATE doc_rate SET doc_rating = %s WHERE docrate_id = %s",
quote_smart($reset),
quote_smart($id));
$change_result = mysql_query($change_rating) or die ("ERROR: Unable to reset rating");
}
}
?>
The first foreach function should retrieve the docrate_id as well as the number which is being submitted from the dropdown menu.
And the second foreach should retrieve the doc_id and the value 0.
Jermizzle