Jump to content

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'];
}
?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.