Jump to content

[SOLVED] what is the mistake in this script


jck

Recommended Posts

<?
require_once("conn.php");

//check the user ???
$q1 = "select * from dd_rating where ItemID = '$_POST[itemID]' and username = '$_SESSION[username]' ";
$r1 = mysql_query($q1) or die(mysql_error());

if(mysql_num_rows($r1) == '0')
{

$q2 = "insert into dd_rating set 
				ItemID = '$_POST[itemID]',
				Rating = '$_POST[rr]',
				username = '$_SESSION[username]' ";
mysql_query($q2) or die(mysql_error());

       $q3 = "select rating from dd_items where ItemID = '$_POST[itemID]' ";

       $r3 = mysql_query($q3);
       $rating = mysql_fetch_array($r3);

       $q4 = "select ratecount from dd_items where ItemID = '$_POST[itemID]'";  
       $r4 = mysql_query($q4)
       $ratecount = mysql_fetch_array($r4);

       $ratecountn = $ratecount + 1; 
       $ratingn = $rating*$ratecount/$ratecountn;
       $q5 = "UPDATE dd_items SET rating='$ratingn where ItemID = '$_POST[itemID]'";
       $r5 = mysql_query($q5);


header("location:$_SERVER[HTTP_REFERER]&rate_error=n");

      




}
else
{
header("location:$_SERVER[HTTP_REFERER]&rate_error=y");
}


?>

somebody please answer

 

What is the question/problem? There is neither in the post above.

 

 

If you want help/an answer please post what is going wrong, where you think it is going wrong and what steps you have already taken to fix it.

the script is nor working

 

Not going to work. Why isn't it working, how isn't it working. What part about it do you think is not working?

 

This isn't, here is a bunch of code, find the error for me forum. This is the help forum. We will help you, but first you need to put forth the effort and ask the question the right way.

 

Just informing you that you won't get an answer till you are clearer on the issue and not just say "Here is a haystack, please find the needle for me."

try

<?
session_start();
require_once("conn.php");

//check the user ???
$q1 = "select * from dd_rating where ItemID = '$_POST[itemID]' and username = '$_SESSION[username]' ";
$r1 = mysql_query($q1) or die(mysql_error());

if(mysql_num_rows($r1) == '0') {
// update db
$q2 = "insert into dd_rating set 
				ItemID = '$_POST[itemID]',
				Rating = '$_POST[rr]',
				username = '$_SESSION[username]' ";
mysql_query($q2) or die(mysql_error());
echo 'rating updated'; 
} else echo 'You can not vote for ',$_POST['ItemID'];
$q3 = "select count(*) as count, sum(Rating) as total, avg(Rating) AS av_rate from dd_items where ItemID = '$_POST[itemID]' ";
$r3 = mysql_query($q3);
$rating = mysql_fetch_array($r3);
if (mysql_num_rows($rating) == 0) echo $_POST['ItemID'] , 'has no votes';
else {
echo ' voting for ', $_POST['ItemID'],'<br />', 
'total points: ', $rating['total'], '<br />',
'num of vaters: ', $rating['count'], '<br />',
'average: ', $rating['av_rate'];
}
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.