This form seems to hate me with somesort of burning passion of a thousand suns. Either it picks up the wrong ID in the form tag (12? 9? Where is it getting these numbers...?) or it's trying to insert into the wrong table, even though I specified that it needs to go into "reviews". It wants to put it into "products".
I am completely out of ideas and will worship the keyboard you type upon for any help. You know you want the worship.
<?
# setup SQL statement to get all the categories
$SQL = " SELECT * FROM products, products_categories";
$SQL .= " WHERE products.id = products_categories.product_id";
$SQL .= " AND products_categories.product_id =".$cat;
# execute SQL statement
$resultSet = mysql_db_query($db, $SQL, $cid);
# check for errors
if (!$resultSet) { echo( mysql_error()); }
else {
if ($REQUEST_METHOD=="POST") {
# setup SQL statement
$SQL = " INSERT INTO reviews ";
$SQL = $SQL . " (product_id, visitor_name, visitor_rating, visitor_review) VALUES ";
$SQL = $SQL . " ('$product_id', '$visitor_name', '$visitor_rating','$visitor_review') ";
# double-up apostrophes
$name = str_replace("'","''",$visitor_name);
$description = ereg_replace("A-Za-z'~*():^_;><", "", $visitor_review);
#execute SQL statement
$result = mysql_db_query($db,"$SQL",$cid);
# check for error
if (!$result) { echo("ERROR: " . mysql_error() . "\n$SQL\n");
}
# display results
while ($row = mysql_fetch_array($resultSet)) {
# syntax
# $variableName = $row["columnName"]
$id = $row["id"];
}
}
echo ("<center><B>Add Your Review</b><br>\n");
echo ("<table>\n");
echo ("<form name=review action=http://totallychibi.com/ztest/catIndex2.php?cat=".$id." method=POST> ");
?>
<?
# setup SQL statement to see the review submit form
$SQL = " SELECT * FROM reviews";
# execute SQL statement
$resultSet = mysql_db_query($db, $SQL, $cid);
# check for errors
if (!$resultSet) { echo( mysql_error()); }
else {
}
# display results
while ($row = mysql_fetch_array($resultSet)) {
# syntax
# $variableName = $row["columnName"]
$product_id = $row["product_id"];
$visitor_rating = $row["visitor_rating"];
$visitor_review = $row["visitor_review"];
$Visitor_name = $row["Visitor_name"];
$id = $row["id"];
}
echo ("<tr><td><b>Your Name:</b> </td><td align='right'><input type='text' name='visitor_name'
size='20'></td></tr>\n");
echo ("<tr><td><b>Rating: </b> </td><td colspan='4'><select name='visitor_rating'>\n");
echo ("<option value='0'>0 Stars</option>\n");
echo ("<option value='0h'>.5 Stars</option>\n");
echo ("<option value='1'>1 Stars</option>\n");
echo ("<option value='1h'>1.5 Stars</option>\n");
echo ("<option value='2'>2 Stars</option>\n");
echo ("<option value='2h'>2.5 Stars</option>\n");
echo ("<option value='3'>3 Stars</option>\n");
echo ("<option value='3h'>3.5 Stars</option>\n");
echo ("<option value='4'>4 Stars</option>\n");
echo ("<option value='4h'>4.5 Stars</option>\n");
echo ("</select></td></tr>\n");
echo ("<tr><td><b>Review: </b></td></tr>\n");
echo ("<tr><td colspan='4'><textarea cols='30' rows='5'
name='visitor_review'></textarea></td></tr>\n");
}
?>
<?
# setup SQL statement to make it work I hope
$SQL = " SELECT * FROM products, products_categories";
$SQL .= " WHERE products.id = products_categories.product_id";
$SQL .= " AND products_categories.product_id =".$cat;
# execute SQL statement
$resultSet = mysql_db_query($db, $SQL, $cid);
# check for errors
if (!$resultSet) { echo( mysql_error()); }
else {
# display results
while ($row = mysql_fetch_array($resultSet)) {
# syntax
# $variableName = $row["columnName"]
$id = $row["id"];
}
echo ("<tr><td><input type='hidden' name='product_id' value=".$id."></td></tr>\n");
echo ("<tr><td colspan='2'><input type='submit' value='Add My Review! (Click ONCE)'></td></tr>\n");
echo ("</table></form>\n");
echo ("</center>");
}
?>