Hello, I have a problem with a code that is meant to allow users to rate content that is loaded from a MySQL database. Since it isn't commented, I should explain most of it here. The page will load content based on the value of the dis that is passed to it via the url. It will then show a the content, and at the bottom I have a form, which is meant to allow readers to rate it, and also fill out a comments sheet that will then be mailed to my address. I've only included one of the php snippets on the page (the one after the form that deals with what the form passes it from $PHP_SELF.
My problem is that it succeeds in deleting the entry, but it fails to write it back into the database. I am doing it this way because I wasn't able to get the MySql change command to work. I would really appreciate any help on this, because I am absolutely stumped on why it wont function right.
| Code: |
|
<?php $name = $_POST['name']; $rating = $_POST['rating']; $readercomment = $_POST['readercomment']; if ($rating) { mysql_connect("localhost", "******", "*******") or die(mysql_error()); mysql_select_db("*******") or die(mysql_error()); $data = mysql_query("SELECT * FROM documents WHERE docname='$docname'") or die(mysql_error()); $info = mysql_fetch_array( $data ); $avgrate = $info['avgrate']; $ratenum = $info['ratenum']; $docname = $info['docname']; $newnum = 1 + $ratenum; $newavg = ($avgrate * $ratenum + $rating)/$newnum; $title = $info['title']; $comments = $info['comments']; $date = $info['date']; $summary = $info['summary']; $type = $info['type']; $content = $info['content']; mysql_query("DELETE FROM documents WHERE docname='$docname' AND title='$title'") or die(mysql_error()); mysql_query("INSERT INTO documents VALUES ( '$title', '$type', '$date', '$content', '$docname', '$summary', '$comments', '$newavg', '$newnum')") or die(mysql_error()); echo "<br>Thank you, " . $_POST['name'] . ", your rating has been submitted.<br>"; } if ($readercomment) { mail('saysior@yahoo.com',$info['title'],$readercomment, "From: " . $name . " And Rated it: " . $rating); echo "<br>Thank you, " . $name . ", your comment has been submitted."; } ?> |
My problem is that it succeeds in deleting the entry, but it fails to write it back into the database. I am doing it this way because I wasn't able to get the MySql change command to work. I would really appreciate any help on this, because I am absolutely stumped on why it wont function right.
