Rating and Hits problem

Hi to all,

In my page rating is working perfectly but when I clicking rating (radio button) the page refreshing and calculating hits and rating

This is my Hits code for my page:


// count more value
$addcounter=$count+1;
$sql2="update $tbl_name set count='$addcounter' WHERE bname = '".$id."'";
$result2=mysql_query($sql2);

rating area


echo '<table align="left" cellspacing="5" cellpadding="5" bgcolor="white" width="100%" border="0">
<tr><td>';
 require "ratingck.php";
 require "disp.php"; 

 echo '<table align="center" cellspacing="5" cellpadding="5" bgcolor="#ECF1EF" width="100%" border="0">
<tr>
<td bgcolor="#2F4F4F"><font size="3" color="white"><b>Rate It</b></a></td></tr>
</table>
';
 require "rating.php";
echo'
</td>
</tr>
</table>

any one help me here

So what’s exactly happening? Your pressing the radio button and nothing is happening? Could you explain in a little more detail…

Thank you replay here.
In index page I am listing some children names, Visitor can select any children name they will get child details in child_list.php. In child_list.php I am showing child details and how many visitor hit the child page (Hits as count). and rating option i used in. when I select rate button in child_list.php I want to calculate rating only not calculate hits (hits only per visiting count) can you understanding my explanation.

rating.php code:


echo "<TABLE width=95% border=0 align=center cellpadding=0 cellspacing=0 > ";
echo "<form name=f1 action='' method=post>";
//echo "<input type=hidden name=id value='$id'>";
echo "<input type=hidden name=todo value='submit-rating'>";
echo "<tr><td ><INPUT TYPE=RADIO NAME=rone Value=1 onClick='f1.submit()';><img src=images/star.gif>1</td>";
echo "<td><INPUT TYPE=RADIO NAME=rone Value=2 onClick='f1.submit()';><font color=#343423><img src=images/star.gif><img src=images/star.gif>2</font></td>";

echo "<td ><INPUT TYPE=RADIO NAME=rone Value=3 onClick='f1.submit()';><font color=#343432><img src=images/star.gif><img src=images/star.gif><img src=images/star.gif>3</font></td>";

echo "<td ><INPUT TYPE=RADIO NAME=rone Value=4 onClick='f1.submit()';>";
echo "<img src=images/star.gif><img src=images/star.gif><img src=images/star.gif><img src=images/star.gif>4</td>";

echo "<td ><INPUT TYPE=RADIO NAME=rone Value=5 onClick='f1.submit()';><img src=images/star.gif><img src=images/star.gif><img src=images/star.gif><img src=images/star.gif><img src=images/star.gif>5</td></tr>";
echo" </td>	</tr></form></table></center> ";

?>

Please check any one my code. I already explained about my problem on above post

this is my child_list.php code:



<?php
$id = addslashes(strip_tags($_GET['id']));
$host="localhost"; // Host name
$username="xxxx"; // Mysql username
$password="xxxx"; // Mysql password
$db_name="kids"; // Database name
$tbl_name="ca_kids"; // Table name

// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect to server ");
mysql_select_db("$db_name")or die("cannot select DB");
$bname = addslashes(strip_tags($_GET['id']));
$sql=("SELECT * FROM $tbl_name   WHERE bname = '".$id."'");
$result= mysql_query($sql);
$rows=mysql_fetch_array($result);
$count=$rows['count'];
$nov=$rows['nov'];
$rating=$rows['rating'];
$bname = mysql_escape_string($rows['bname']);
$fname = mysql_escape_string($rows['fname']);
$mname = mysql_escape_string($rows['mname']);
$age = mysql_escape_string($rows{'age'});

// if have no counter value set counter = 1

$result1=mysql_query($sql1);

//display chinld name and Hits
echo  '<tr>  </tr>
<table  width="100%" border="0" cellpadding="0" cellspacing="0">
  <tbody>
    <tr>
      <td colspan="2" class="secondtableheadtd" style="color: rgb(255, 255, 255);" align="center" background="../images/tab-bg.png" height="20"><font size="3" color="white">'.$rows['bname'].' || Hits:'.$rows['count'].'</font>
	  </td>
    </tr>
</tbody>
</table>

';

//Display child image and information
echo'<table align="left" cellspacing="5" cellpadding="5" bgcolor="#ECF1EF" width="100%" border="0">
<tr><td rowspan=9 bgcolor="" align="left"><img src="http://localhost/polite/kids/images/' . $rows['image'] . '" alt="No Image" width="370" height="250" border="2px" bordercolor="white"></td></tr>
</table>



<table align="center" cellspacing="5" cellpadding="5" bgcolor="#ECF1EF" width="100%" border="0">
<tr>
      <th colspan="2" bgcolor="#2F4F4F" align="left"><font size="2" color="white">Child Information</font></th>
    </tr>
<tr><th align="left" width="90px" bgcolor="#FFFFFE">Child Name</th> <td>'.$bname.'</td></tr>

<tr><th align="left" width="90px" bgcolor="#FFFFFE">Father Name</th> <td>'.$fname.'</td></tr>

<tr><th align="left" width="90px" bgcolor="#FFFFFE">Mother Name</th> <td>'.$mname.'</td></tr>

<tr><th align="left" width="90px" bgcolor="#FFFFFE">Age</th> <td>'.$age.'</td></tr>



<table align="center" cellspacing="5" cellpadding="5" bgcolor="#ECF1EF" width="100%" border="0">
<tr>
<td bgcolor="#2F4F4F"><font size="3" color="white"><b>Rating For This Chaild</b></a></td></tr>
</table>
';
//Display Rating 
echo '<table align="left" cellspacing="5" cellpadding="5" bgcolor="white" width="100%" border="0">
<tr><td>';
 require "ratingck.php";
 require "disp.php"; 

 echo '<table align="center" cellspacing="5" cellpadding="5" bgcolor="#ECF1EF" width="100%" border="0">
<tr>
<td bgcolor="#2F4F4F"><font size="3" color="white"><b>Rate It</b></a></td></tr>
</table>
';
 require "rating.php";
echo'
</td>
</tr>
</table>
';


// count more value (Hits count)
$addcounter=$count+1;
$sql2="update $tbl_name set count='$addcounter' WHERE bname = '".$id."'";
$result2=mysql_query($sql2);
 
mysql_close();

?>



The first thing I see right off hand is the form method is POST and you are using $_GET[‘id’].
Change the $_GET[‘id’] to $_POST[‘id’] and see what error you get if any. Then come back and we’ll see.
Thanks,
Kevin

Hi,

I see this:



// Is this really needed? Should $bname = id?
$bname = addslashes(strip_tags($_GET['id']));

// on the query below, I don't think you need the quotes around $id.
// $sql=("SELECT * FROM $tbl_name   WHERE bname = '".$id."'");

$sql=("SELECT * FROM $tbl_name   WHERE bname = '$id' ");

$result= mysql_query($sql);

$rows=mysql_fetch_array($result);

$count=$rows['count'];

$nov=$rows['nov'];

$rating=$rows['rating'];

$bname = mysql_escape_string($rows['bname']);

$fname = mysql_escape_string($rows['fname']);

$mname = mysql_escape_string($rows['mname']);

// below you put { instead of [
// $age = mysql_escape_string($rows{'age'});

$age = mysql_escape_string($rows['age']);


Need more coffee to go over rest.

Thanks,
Kevin

Kevin Thank u replay here.
I am getting all data correct from database my main problem with rating button when I clicking the radio button the page refreshing and calculating page visiting count (Hits). I do not want to calculate Hits when I clicking the radio button this is only for rating. Hits count only when I choosing a name of the child in index page the page count will be calculate

I am sorry, this is beyond my scope. Maybe someone with a little more expertise can help.
Thanks,
Kevin

Its OK!
I improved my code ok. I have one more question?

How can allow the only one vote for the visitor I added IP field in my column this is my rate code.


<? 
$babyid = addslashes(strip_tags($_GET['babyid']));
require "config.php"; 
@$todo=$_POST['todo'];
if(isset($todo) and $todo=="submit-rating"){
$rone=$_POST['rone'];

$msg="";
$status="OK";
if(!isset($rone)){$msg=$msg."Pleae give your score and then click the button";
$status="NOT OK";
}				


if ($status=="OK")
{

$result=mysql_query("SELECT rating,nov FROM ca_kids WHERE bname = '".$babyid."'");
$rows=mysql_num_rows($result);
$row=mysql_fetch_object($result);

if($rows==0){
// This is a new page so first add a new record
$tt=mysql_query("insert into ca_kids (babyid,nov,rating) values ( $babyid,1,$rone)");
}

else {
$rating=$row->rating;
$nov=$row->nov + 1;		
$status="OK";

$rating=$rating+$rone;

	$result=mysql_query("update ca_kids set rating=$rating,nov=$nov where bname = '".$babyid."'");

}	
}else{echo $msg;}
}// end of todo checking
?>