|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
|
|
Stay one step ahead of the competition. Evaluate and give feedback
on some of the hottest web development tools on the market today.
Make your opinion heard! Click
Here
|
|
#1
|
|||
|
|||
|
Photolog Rating Problem
win 98 localhost
i am trying to rate photos and store rating info in mysql i need some general guidance. when i click on the thumb, it takes me to comments.php which displays the full photo, the rating drop down box, and the comment form along with this in the url box: http://localhost/comments.php?id=19_0_1_0_C These Things are all Correct But, when i try to rate the photo, it gives a blank page with this in the url box: http://localhost/rate.php?post_id= can anyone give me any ideas about what could be causing this problem here is the code if it helps: rateform.php: <html> <head></head> <body> <?php // Define Database Connection Variables $hostname="localhost"; $dbusername="xxx"; $dbpassword="xxxx"; $dbname="xxxx"; $connection=mysql_connect($hostname,$dbusername,$d bpassword ); $q="SELECT * FROM pm_weblog"; $result= mysql_db_query($dbname, $q, $connection); if(!$result) { $error_number = mysql_errno(); $error_msg = mysql_error(); echo "MySQL error $error_number: $error_msg"; } while ($row=mysql_fetch_array($result)) { $post_id=$result["post_id"]; } ?> <form action="<?php echo "rate.php?post_id=$post_id"; ?>" method="post"> <select name="Rate"> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> <option value="5">5</option> <option value="6">6</option> <option value="7">7</option> <option value="8">8</option> <option value="9">9</option> <option value="10">10</option> </select> <input type="submit" value="Rate"> </form> </body> </html> rate.php: <?php // database variables $hostname="localhost"; $dbusername="xxxx"; $dbpassword="xxxx"; $dbname="xxxxx"; $connection=mysql_connect($hostname,$dbusername,$d bpassword ); $q="SELECT * FROM pm_weblog WHERE post_id='$post_id' "; $result= mysql_db_query($dbname, $q, $connection); if(!$result) { $error_number = mysql_errno(); $error_msg = mysql_error(); echo "MySQL error $error_number: $error_msg"; } while ($row=mysql_fetch_array($result)) { $post_id=$row["post_id"]; $Num_Votes=$row["Num_Votes"]; $Votes_Tally =$row["Votes_Tally"]; $Rating=$row["Rating"]; $new_Votes=$Num_Votes+1; $Votes_Tally=$Votes_Tally+$Rating; $Rating=round(($Votes_Tally/$new_Votes),1); $q="UPDATE pm_weblog SET Num_Votes='$new_Votes', Votes_Tally='$Votes_Tally', Rating='$Rating' WHERE post_id='$post_id'"; $result2= mysql_db_query($dbname, $q, $connection) or die ("Could not execute query : $q." . mysql_error()); if ($result2) { echo "Thank you. This picture has rating = $Rating after your vote."; } } ?> btw, comments.php contains the function: <?php function rateform() { include("./rateform.php"); } ?> <?php rateform(); ?> thanks in advance. |
|
#2
|
|||
|
|||
|
Have you tried echoing out the value of $post_id:
PHP Code:
Also, just out of curiosity, is the rateform.php page a form for ALL images on one page, or just for a specific image? The reason I'm asking is because your SQL query on the rateform.php page is: "SELECT * FROM pm_weblog" which will return ALL the values in that table.
__________________
____________________________________________ Developer Shed Weekly Writer | DevArticles Forum Moderator Build Your Own KlipFolio Klip With PHP FrankManno.com - Under Construction Design Interactive Group - Under Construction |
|
#3
|
|||
|
|||
|
btw, i'm running php4.2.3 with global register and magic quotes=off on abyss web server
"is the rateform.php page a form for ALL images on one page, or just for a specific image?" it's for each image. i fixed the query in the updated script below. i've gotten the id to appear in the url: http://localhost/rate.php?post_id=14 also, Num_Votes info IS being inserted into mysql, but Votes_Tally and Rating are NOT. but, now when i try to rate the photo, it gives me this: Thank you. This picture has rating = 0 after your vote. which, of course, is the echo line at the bottom of rate.php. here are the UPDATED scripts: rateForm.inc.php(located in my 'scripts' directory and is called in comments.php) <?php function rateForm ($entryid = "") { // Grab the current id from the // URL variable string if (substr($entryid, 0, 1) == "X") { $entryid = substr($entryid, 1); } $x1 = explode("_",$entryid); $post_id = $x1['0']; ?> <form name="rateArtwork" action="rate.php?post_id=<?php echo $post_id; ?>" method="post"> <select name="Rate" id="Rate"> <option value="1">1 (low)</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> <option value="5">5</option> <option value="6">6</option> <option value="7">7</option> <option value="8">8</option> <option value="9">9</option> <option value="10">10 (high)</option> </select> <input type="submit" name="value="Rate" /> </form> <?php } //end function ?> rate.php <?php // Grab the passed variables $post_id = $_GET['post_id']; $Rate = $_POST['Rate']; // Check to see if the Rating is really even set. // If not, don't proceed. if ((empty($Rate)) || ($Rate == "") || ($Rate < 1)) { echo "Your image rating was not correctly set. Please go back and try again."; } else { // database variables $hostname="localhost"; $dbusername="xxxx"; $dbpassword="xxxx"; $dbname="xxxx"; $connection=mysql_connect($hostname,$dbusername,$d bpassword ); $q="SELECT * FROM pm_weblog WHERE post_id='$post_id'"; $result= mysql_db_query($dbname, $q, $connection); if(!$result) { $error_number = mysql_errno(); $error_msg = mysql_error(); echo "MySQL error $error_number: $error_msg"; } while ($row = mysql_fetch_array($result)) { $post_id = $row["post_id"]; $Num_Votes = $row["Num_Votes"]; $Votes_Tally = $row["Votes_Tally"]; $Rating = $row["Rating"]; $new_Votes = $Num_Votes + 1; $Votes_Tally = $Votes_Tally + $Rating; $Rating = round(($Votes_Tally/$new_Votes),1); $q = "UPDATE pm_weblog SET " . "Num_Votes = '$new_Votes', " . "Votes_Tally = '$Votes_Tally', " . "Rating = '$Rating' " . "WHERE post_id = '$post_id'"; $result2 = mysql_db_query($dbname, $q, $connection) or die ("Could not execute query : $q." . mysql_error()); if ($result2) { echo "Thank you. This picture has rating = $Rating after your vote."; } } // end while } // End Main Else ?> |
|
#4
|
|||
|
|||
|
PHP Code:
You don't need to enclose your numeric-value variables in quotes... Try this: PHP Code:
Give it a try... What errors are you receiving, if any? |
|
#5
|
|||
|
|||
|
thanks for your reply. i messed around with the code a bit and got it to work
![]() |
|
#6
|
|||
|
|||
|
No problem... What was it?
|
![]() |
| Viewing: Dev Articles Community Forums > Programming > General Programming Help > Photolog Rating Problem |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|