I have one more problem. I have used the coding above on another rating system, but i keep on getting an error:
ERROR:Unable To Run UPDATE doc_data SET tech_rating = tech_rating + 'selected', num_of_votes = num_of_votes + 1 WHERE doc_id = 1 Truncated incorrect DOUBLE value: 'selected'
I do not know why this is coming up because i have used the exact same coding, but i have only changed the variables which it is supposed to use.
I have more than one page which rates documents in the table so there will be several rows including Technical Rating and Financial Rating.
Here is the coding for the pages.
this is for the techincal form
$host = "localhost";
$user = "root";
$pass = "mysql";
$db = "brainstorm";
$connection = mysql_connect($host,$user,$pass) or die ("ERROR:Unable To Connect".mysql_error());
mysql_select_db($db) or die ("ERROR:Unable To Connect To DB".mysql_error());
$query = "SELECT * FROM doc_data ORDER BY session ";
$result = mysql_query($query) or die ("ERROR:Unable To Run Query".mysql_error());
echo "<h3><font face=Verdana>Department: Technical</h3>";
#if (mysql_num_rows($result) > 0) {
echo "<form name=ratings method=POST action=btable.php>";
echo "<table border=1 cellpadding=3 cellspacing=3>";
echo "<tr>";
echo "<td><font face=Verdana size=-1><b>Session</b></font></td>";
echo "<td><font face=Verdana size=-1><b>Title of Brainstorm Idea</b></font></td>";
echo "<td><font face=Verdana size=-1><b>Inventor Name</b></font></td>";
echo "<td><font face=Verdana size=-1><b>Rating</b></font></td>";
echo "<td><font face=Verdana size=-1><b>Status</b></font></td>";
echo "</tr>";
while ($row=mysql_fetch_assoc($result)){
echo "<tr>";
echo "<td><p align=center><font face=Verdana size=-1>".$row['session']."</center></td>";
echo "<td><font face=Verdana size=-1><a href=http://www.SHTC.com/$row[url]><font face=Verdana size=-1>".$row['idea']."</td>";
echo "<td><font face=Verdana size=-1>".$row['inventor_name']."</td>";
echo "<td><select name=".$row['doc_id']."> <option value= 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>";
if ($row['tech_rating'] > 0){
echo "<td><p align=center><img src=reddot.gif name=already_rated height=10px width=10px></td>";
} else {
echo "<td><p align=center><img src=bluedot.gif name=need_rating height=10px width=10px></td>";
}
echo "</tr>\n";
}
echo "</table>\n";
echo "<br>";
echo "<input type=submit name=submit value=submit><br><br>";
echo "</form>";
echo "<font face=Verdana size=-1><a href=http://localhost/brainstorm/index.php>Back to Form</a>";
this is the form for the finance page.
$host = "localhost";
$user = "root";
$pass = "mysql";
$db = "brainstorm";
$connection = mysql_connect($host,$user,$pass) or die ("ERROR:Unable To Connect".mysql_error());
mysql_select_db($db) or die ("ERROR:Unable To Connect To DB".mysql_error());
$query = "SELECT * FROM doc_data ORDER BY session ";
$result = mysql_query($query) or die ("ERROR:Unable To Run Query".mysql_error());
echo "<h3><font face=Verdana>Department: Finance</h3>";
#if (mysql_num_rows($result) > 0) {
echo "<form name=ratings method=POST action=btable.php>";
echo "<table border=1 cellpadding=3 cellspacing=3>\n";
echo "<tr>";
echo "<td><font face=Verdana size=-1><b>Session</b></font></td>";
echo "<td><font face=Verdana size=-1><b>Title of Brainstorm Idea</b></font></td>";
echo "<td><font face=Verdana size=-1><b>Inventor Name</b></font></td>";
echo "<td><font face=Verdana size=-1><b>Rating</b></font></td>";
echo "<td><font face=Verdana size=-1><b>Status</b></font></td>";
echo "</tr>\n";
while ($row=mysql_fetch_assoc($result)){
echo "<tr>";
echo "<td><p align=center><font face=Verdana size=-1>".$row['session']."</center></td>";
echo "<td><font face=Verdana size=-1><a href=http://www.SHTC.com/$row[url]><font face=Verdana size=-1>".$row['idea']."</td>";
echo "<td><font face=Verdana size=-1>".$row['inventor_name']."</td>";
echo "<td><select name=".$row['doc_id']."> <option value= '' 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>";
if ($row['fin_rating'] > 0){
echo "<td><p align=center><img src=reddot.gif name=already_rated height=10px width=10px></td>";
} else {
echo "<td><p align=center><img src=bluedot.gif name=need_rating height=10px width=10px></td>";
}
echo "</tr>\n";
}
echo "</table>\n";
echo "<br>";
echo "<input type=submit name=submit value=submit><br><br>";
echo "</form>";
echo "<font face=Verdana size=-1><a href=http://localhost/brainstorm/index.php>Back to Form</a>";
And here is the coding for the table which displays the data
$host = "localhost";
$user = "root";
$pass = "mysql";
$db = "brainstorm";
$connection = mysql_connect($host,$user,$pass) or die ("ERROR:Unable To Connect".mysql_error());
mysql_select_db($db) or die ("ERROR:Unable To Connect To DB".mysql_error());
$query = "SELECT * FROM doc_data ORDER BY session ";
$result = mysql_query($query) or die ("ERROR:Unable To Run Query".mysql_error());
echo "<table border=1 cellpadding=3 cellspacing=3>";
echo "<tr>";
echo "<td><font face=Verdana size=-1><b>Session</b></font></td>";
echo "<td><font face=Verdana size=-1><b>Title of Brainstorm Idea</b></font></td>";
echo "<td><font face=Verdana size=-1><b>Inventor Name</b></font></td>";
echo "<td><font face=Verdana size=-1><b>Technical Rating</b></font></td>";
echo "<td><font face=Verdana size=-1><b>Finance Rating</b></font></td>";
echo "</tr>";
while ($row=mysql_fetch_assoc($result)){
echo "<tr>";
echo "<td><p align=center><font face=Verdana size=-1>".$row['session']."</center></td>";
echo "<td><font face=Verdana size=-1><a href=http://pws.stonehouse.oilfield.slb.com/SHTC/SER/IP-1/August_2006_Brainstorm/$row[url]><font face=Verdana size=-1>".$row['idea']."</td>";
echo "<td><font face=Verdana size=-1>".$row['inventor_name']."</td>";
echo "<td><font face=Verdana size=-1>".$row['tech_rating']."</td>";
echo "<td><font face=Verdana size=-1>".$row['fin_rating']."</td>";
echo "</tr>";
}
echo "</table>";
echo "<br>";
echo "<font face=Verdana size=-1><a href=http://localhost/brainstorm/index.php>Back to Form</a>";
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 ($_POST as $doc_id => $tech_rating){
if ($doc_id == 'submit') {
exit();
} //exits when it gets to submit
$update_table =sprintf("UPDATE doc_data SET tech_rating = tech_rating + %s, num_of_votes = num_of_votes + 1 WHERE doc_id = %s",
quote_smart($tech_rating),
quote_smart($doc_id));
$result = mysql_query($update_table) or die("ERROR:Unable To Run $update_table".mysql_error());
}
foreach ($_POST as $doc_id => $fin_rating){
if ($doc_id == 'submit'){
exit();
}//exits when it gets submit
$update_table =sprintf("UPDATE doc_data SET fin_rating = fin_rating + %s, num_of_votes = num_of_votes + 1 WHERE doc_id = %s",
quote_smart($fin_rating),
quote_smart($doc_id));
$result = mysql_query($update_table) or die ("ERROR:Unable To Run $update_table".mysql_error());
}
?>
Can anyone see what is wrong. I think the error is saying that the variable is being saved as text when it is supposed to be a number.
Thanks