General Programming Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingGeneral Programming Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
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  
Old December 20th, 2002, 12:03 PM
DivaX007 DivaX007 is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2002
Posts: 23 DivaX007 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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.

Reply With Quote
  #2  
Old December 21st, 2002, 10:04 PM
FrankieShakes FrankieShakes is offline
Frank The Tank!
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: Jun 2002
Location: Toronto, Canada
Posts: 1,246 FrankieShakes User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 8
Send a message via ICQ to FrankieShakes Send a message via MSN to FrankieShakes
Have you tried echoing out the value of $post_id:

PHP Code:
while ($row=mysql_fetch_array($result))
{
$post_id=$result["post_id"];


echo 
$post_id


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

Reply With Quote
  #3  
Old December 21st, 2002, 11:36 PM
DivaX007 DivaX007 is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2002
Posts: 23 DivaX007 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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

?>

Reply With Quote
  #4  
Old December 23rd, 2002, 12:29 PM
FrankieShakes FrankieShakes is offline
Frank The Tank!
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: Jun 2002
Location: Toronto, Canada
Posts: 1,246 FrankieShakes User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 8
Send a message via ICQ to FrankieShakes Send a message via MSN to FrankieShakes
PHP Code:
 $q "UPDATE pm_weblog SET " .
          
"Num_Votes = '$new_Votes', " .
          
"Votes_Tally = '$Votes_Tally', " .
          
"Rating = '$Rating' " .
        
"WHERE post_id = '$post_id'"


You don't need to enclose your numeric-value variables in quotes... Try this:
PHP Code:
 $q "UPDATE pm_weblog SET Num_Votes = $new_Votes, Votes_Tally = $Votes_Tally, Rating = $Rating WHERE post_id = $post_id"


Give it a try... What errors are you receiving, if any?

Reply With Quote
  #5  
Old December 25th, 2002, 10:08 PM
DivaX007 DivaX007 is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2002
Posts: 23 DivaX007 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
thanks for your reply. i messed around with the code a bit and got it to work

Reply With Quote
  #6  
Old December 27th, 2002, 10:18 AM
FrankieShakes FrankieShakes is offline
Frank The Tank!
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: Jun 2002
Location: Toronto, Canada
Posts: 1,246 FrankieShakes User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 8
Send a message via ICQ to FrankieShakes Send a message via MSN to FrankieShakes
No problem... What was it?

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingGeneral Programming Help > Photolog Rating Problem


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway