hi all ,

I was developing a blog where in admin control panel i can view the new comments.
i want to set the approval to view the comments in the blog.

problem is I used radio buttons to set permision but it did n't work properly.

I need to view the radio buttons checked according to the data base value.

i have a field name allow_cm in the data base which gives if comments is approved other wise 0.

I used ajax to make it more user friendly but when I print the comment only the last row radio button is checked.

how to solve this.

here is the code viewing comments

$qry3="select * from usercomments";
         $result=mysql_query($qry3);
             echo '<table  border=1 align="center">'.'<thead>'.'<tr>'.'<th>'."PO_ID".'</th>';
             echo '<th>'."C_ID".'</th>'.'<th>'."USER_NAME".'</th>'.'<td width=300; align="center">'."COMMENT".'</th>';
             echo '<th>'."DATE".'</th>';
             echo '<th>'."ALLOW".'</th>';
             echo '<th>'.'DEL'.'</th>'.'</tr>';
             echo '</thead>';
         while($row=mysql_fetch_array($result)){
            echo '<tbody>';
            echo '<tr>'.'<td align="center" >'.$row['postId'].'</td>';
            echo '<td align="center" >'.$row['commentId'].'</td>';
            echo '<td align="center" >'.$row['name_cm'].'</td>';
            echo '<td align="center" >'.$row['comment_cm'].'</td>';
            echo '<td align="center" >'.$row['dateComment_cm'].'</td>';
            echo '<td align="center" >';
            $radioval=$row['allow_cm'];
            if($radioval==1){
                
              echo "Yes".'<input type="radio" name="yes" value="1" checked="checked" onclick="callChange(this.value)"/>';
              echo "No". '<input type="radio" name="no" value="0" onclick="callChange(this.value)"/>';
                
            }else{
              echo "Yes".'<input type="radio" name="yes" value="1"  onclick="callChange(this.value)"/>';
              echo "No". '<input type="radio" name="no" value="0" checked="checked" onclick="callChange(this.value)"/>';   
            
                
            }
            echo '</td>';
            
            $cmId=$row['commentId'];
            $poId=$row['postId'];
            echo "<td align='center'><input type='button' value='Del' id='del'.'$cmId'.'$poId' onclick='delcomment(".$cmId.",".$poId.")'>"."</td>";
            echo '</tr>';

this is the javascript I used.

function callChange(str)
{
if (str=="")
  {
  document.getElementById("contentbox").innerHTML="";
  return;
  } 
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("contentbox").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","delete.php?q3="+str,true);
xmlhttp.send();
}

thx in advance,menuka

this is the severer side code

$dob = new DBhandling(dbHost,dbUser,dbName,dbPass);
  $dob->connectDB();
//echo "inId is".$inId;
 //get the comment id and accordingly data will be recorded.
  $q=$_GET["q"];//commentId
  $q2=$_GET["q2"];//postId
  $q3=$_GET["q3"];//postId
$sql2="INSERT INTO recyclecomments (postid,commentId,name_cm,email_cm,website_cm,comment_cm,dateComment_cm,allow_cm) SELECT postid,commentId,name_cm,email_cm,website_cm,comment_cm,dateComment_cm,allow_cm
FROM usercomments WHERE commentId='$q'and postid='$q2'";
$sql4="UPDATE usercomments SET allow_cm='$q3'";
mysql_query($sql3);
mysql_query($sql2);

//post is deleted from the thread
$sql="delete FROM usercomments WHERE commentId='$q' and postid='$q2'";
mysql_query($sql) or die(mysql_error());  
mysql_query($sql4) or die(mysql_error());

 
   $qry3="select * from usercomments";
         $result=mysql_query($qry3);
             echo '<table  border=1 align="center">'.'<thead>'.'<tr>'.'<th>'."PO_ID".'</th>';
             echo '<th>'."C_ID".'</th>'.'<th>'."USER_NAME".'</th>'.'<td width=300; align="center">'."COMMENT".'</th>';
             echo '<th>'."DATE".'</th>';
             echo '<th>'."ALLOW".'</th>';
             echo '<th>'.'DEL'.'</th>'.'</tr>';
             echo '</thead>';
         while($row=mysql_fetch_array($result)){
            echo '<tbody>';
            echo '<tr>'.'<td align="center" >'.$row['postId'].'</td>';
            echo '<td align="center" >'.$row['commentId'].'</td>';
            echo '<td align="center" >'.$row['name_cm'].'</td>';
            echo '<td align="center" >'.$row['comment_cm'].'</td>';
            echo '<td align="center" >'.$row['dateComment_cm'].'</td>';
            echo '<td align="center" >';
            $radioval=$row['allow_cm'];
            if($radioval==1){
                
              echo "Yes".'<input type="radio" name="yes" value="1" checked="checked" onclick="callChange(this.value)"/>';
              echo "No". '<input type="radio" name="no" value="0" onclick="callChange(this.value)"/>';
                
            }else{
              echo "Yes".'<input type="radio" name="yes" value="1"  onclick="callChange(this.value)"/>';
              echo "No". '<input type="radio" name="no" value="0" checked="checked" onclick="callChange(this.value)"/>';   
            
                
            }
            echo '</td>';
            
            $cmId=$row['commentId'];
            $poId=$row['postId'];
            echo "<td align='center'><input type='button' value='Del' id='del'.'$cmId'.'$poId' onclick='delcomment(".$cmId.",".$poId.")'>"."</td>";
            echo '</tr>';
        //echo '<form action="delete.php?cmId='.$cmId.'">';

//echo "printr".print_r($row);
           
            
            
            
         }
          echo '</tbody>'.'</table>';
         $dob->closeDB();
        // put your code here



    
}

when I run the project only the last raw view the checked radio and that value efect for all comments
that means if I allow from the admin pannel to one comment all comment can be viewed.

please help me to correct this.

Member Avatar for P0lT10n

You have a very bad problem with you code, you have in the last comment, line 8 9 10 11, few problems... you call in line 11 nothing.... and your syntax is not correct on line 8 9... see here how is the INSERT INTO syntax ! And for AJAX, I recommend you to use jQuery...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.