Hi,

I have this site where user submits their questions and based on the quality I select or reject them. IF the user's submitted qn is selected he get +1 points for 1 questions otherwise none.
But in my admin panel when I get a questions, due to the radio button I can select/reject only one question at a time. It takes me a lot of time since everyday people submit a lot of question. So I want to change the "radio option" to "checkbox option" in the code so that I can select/reject multiple question at once. I have pasted the code. Any help would be really appreciated. IF I am at the wrong forums, could you please suggest me the right place. thanks a lot.


<body>
<?php
print_r($POST);
//if( isset($
REQUEST['hdnAcceptSubmit']) ){

if( isset($_SESSION['user']['email'] ) ){

$counter=0;
?>
<div class="formHeading">List of Questions need to Accept / Reject</div><br/><br/>
<!--<form id="frmAccept" onsubmit="postHTML('mainContent','accept.php', 'frmAccept' )" >-->
<form id="frmAccept" method="post" action="process.php" name="frmAccept">
<div id="topScores">
<div class="header row" style="background-color: <?=($counter%2 == 0)?"#CBD48F": "#CBD481"?>; line-height: 18px; float:left; width:10px;">#</div>
<div class="header row" style="background-color: <?=($counter%2 == 0)?"#CBD48F": "#CBD481"?>; line-height: 18px; float:left; width: 55px;">Name</div>
<div class="header row" style="background-color: <?=($counter%2 == 0)?"#CBD48F": "#CBD481"?>; line-height: 18px; float:left; width: 55px;">Question</div>
<div class="header row" style="background-color: <?=($counter%2 == 0)?"#CBD48F": "#CBD481"?>; line-height: 18px; float:left; width: 75px;">Answer </div>
<div class="header row" style="background-color: <?=($counter%2 == 0)?"#CBD48F": "#CBD481"?>; line-height: 18px; float:left; width: 95px;">Option 1</div>
<div class="header row" style="background-color: <?=($counter%2 == 0)?"#CBD48F": "#CBD481"?>; line-height: 18px; float:left; width: 65px;">Option 2</div>
<div class="header row" style="background-color: <?=($counter%2 == 0)?"#CBD48F": "#CBD481"?>; line-height: 18px; float:left; width: 65px;">Option 3</div>
<br style="clear:both;"/>
<?

$db->connect();

$counter = 1;
$totalpoints = new User();

$sql = "SELECT U.first_name,Q.question,Q.answer,Q.opt_1,Q.opt_2,Q .opt_3,Q.enabled,Q.question_id,Q.user_id FROM ".$db->pre."quiz_questions Q,".$db->pre."quiz_users U WHERE Q.enabled = 0 and Q.user_id = U.user_id";

$results = $db->query($sql);
while ($user = $db->fetch_array($results) ) {
?>

<div class="row" style="background-color: <?=($counter%2 == 0)?"#CBD48F": "#CBD481"?>; line-height: 18px; float:left; width: 10px; padding-top:5px;">
<input type="radio" name="group1" value="<?=$user['question_id']?>" align="absmiddle" /></div>
<input type="hidden" name="<?=$user['question_id']?>" id="<?=$user['question_id']?>" value="<?=$user['user_id']?>" />
<div class="row" style="background-color: <?=($counter%2 == 0)?"#CBD48F": "#CBD4FF"?>; line-height: 18px; float:left; width: 55px;"><?=$user['first_name']?></div>
<div class="row" style="background-color: <?=($counter%2 == 0)?"#CBD48F": "#CBD4FF"?>; line-height: 18px; float:left; width: 55px;"><?=$user['question']?></div>
<div class="row" style="background-color: <?=($counter%2 == 0)?"#CBD48F": "#CBD4FF"?>; line-height: 18px; float:left; width: 75px;"><?=$user['answer']?></div>
<div class="row" style="background-color: <?=($counter%2 == 0)?"#CBD48F": "#CBD4FF"?>; line-height: 18px; float:left; width: 95px;"><?=$user['opt_1']?></div>
<div class="row" style="background-color: <?=($counter%2 == 0)?"#CBD48F": "#CBD4FF"?>; line-height: 18px; float:left; width: 65px;"><?=$user['opt_2']?></div>
<div class="row" style="background-color: <?=($counter%2 == 0)?"#CBD48F": "#CBD4FF"?>; line-height: 18px; float:left; width: 65px;"><?=$user['opt_3']?></div>
<br style="clear:both;"/>
<?
$counter++;
}
//$db->close();
?>
<input type="submit" class="button" style="margin-left: 65px; margin-top: 15px;" value="Accept" id="btnaccept" name="btnaccept" />
<input type="submit" class="button" style="margin-left: 65px; margin-top: 15px;" value="Reject" id="btnreject" name="btnreject"/>

<!-- <input type="hidden" id="hdnAcceptSubmit" name="hdnAcceptSubmit" value="true"/> -->

</div>
</form>
<? } else {?>
<div class="header">Please login to View the Submitted Questions<br/></div>
<?
}
?>

</body>
</html>

    Change your radio button to checkbox like this:

    <input type="checkbox" name="group1[]" value="<?=$user['question_id']?>" align="absmiddle" /></div>
    

    Now when you submit the form, checked checkboxes can be found in $_POST['group1'] array.

    Use the code-tags next time you paste code.

      I did what you said but its not working , its giving some error which is also for less than a sec so I can't see ...

      Actually I didn't know how to use code-tags, I'll take care from next time.

        If your script is redirecting the page to somewhere else in process.php, comment the redirect so you can see the error.

          We'll need to see at least a bit of process.php. What cahva is asking you to do is find a line in that file that says something like "header('Location:....')"; and comment it so it doesn't run.

          Incidentally, you are allowed to use <table> elements to represent tables in HTML. You don't need to fake them with a whole pile of <div>s.

            Here is the process.php file ...

            PS : I didn't fake anything, I just pasted what my previos coder did long time back ... If I had a knowledge of PHP, I would not be asking qns in a forum.

            <?
            session_start();
            include_once("../includes/config.inc.php");
            include_once("../classes/database.class.php");
            include_once("../classes/main.class.php");
            include_once("../includes/functions.inc.php");

            if( isset($POST['btnaccept']) || isset($POST['btnreject'] )) {
            $db = new Database($config['server'],$config['user'],$config['pass'],$config['database'],$config['tablePrefix']);
            $db->connect();
            $accept = $POST['btnaccept'];
            $reject = $
            POST['btnreject'];
            $questionid = $REQUEST['group1'];
            $userid = $
            REQUEST[$questionid];
            if($accept != "") {
            $sql = "UPDATE ".$db->pre."quiz_questions SET enabled = 1 WHERE question_id =".$questionid;
            $db->query($sql);

            		$sql = "SELECT * FROM ".$db->pre."quiz_points WHERE user_id =".$userid ." AND point_type_id = 3";				 
            	$found = $db->query_first($sql); 
            	if( $found ) {	
            			$sql = "select SUM(points) from ".$db->pre."quiz_points where user_id =".$userid;
            			$rows = $db->query($sql);
            			$row = $db->fetch_array($rows);
            			if($row["SUM(points)"] < 4000) {					
            				$sql = "UPDATE ".$db->pre."quiz_points SET points = points + 1 WHERE user_id =".$userid ." AND point_type_id = 3";
            			}	
            	}
            	else {		
            		$sql = "INSERT INTO ".$db->pre."quiz_points (user_id,points,point_type_id,date_added) VALUES(".$userid .", 1, 3,now())";	
            	}

            // echo "Question Accepted Successfully";
            }
            else {
            $sql = "UPDATE ".$db->pre."quiz_questions SET enabled = 2 WHERE question_id =".$questionid;
            // echo "Question Rejected Successfully";
            }
            $db->query($sql);
            $db->close();
            }
            //header("Location:index.php");
            ?>
            <script language="javascript" type="text/javascript">
            window.location="index.php?s=1";
            </script>

              If I had a knowledge of PHP, I would not be asking qns in a forum.

              Well, for one thing, I was talking about the HTML, not the PHP; and having a knowledge about PHP doesn't stop one from having questions (there is an entire forum on this site for people who have no knowledge and want to get started).

              Meanwhile; I see you've commented the header() redirect, but it turns out that it's not enough to comment it out, because then the same thing is done again only with JavaScript. I recommend adding a line to the end of the script thus:

              //header("Location:index.php");
              exit();
              ?>
              <script language="javascript" type="text/javascript">
              window.location="index.php?s=1";
              </script>

              The header() is still commented out because we don't want the redirect to happen yet, because we're still wanting to see what that momentary error message is. Afterwards, we'll be uncommenting it but the exit() should remain.

                If I had a knowledge of PHP, I would not be asking qns in a forum.

                Well, for one thing, I was talking about the HTML, not the PHP; and having a knowledge about PHP doesn't stop one from having questions (there is an entire forum on this site for people who have no knowledge and want to get started).

                Meanwhile; I see you've commented the header() redirect, but it turns out that it's not enough to comment it out, because then the same thing is done again only with JavaScript. I recommend adding a line to the end of the script thus:

                //header("Location:index.php");
                exit();
                ?>
                <script language="javascript" type="text/javascript">
                window.location="index.php?s=1";
                </script>

                The header() is still commented out because we don't want the redirect to happen yet, because we're still wanting to see what that momentary error message is. Afterwards, we'll be uncommenting it but the exit() should remain.

                  One thing that you havent taken into consideration is that $REQUEST['group1'] is now an array(if one of them is selected). Add a check that there is at least one selected. You can check if checkboxes are populated like this:

                  if (!empty($_POST['group1']) && is_array($_POST['group1'])) {
                      // group1 has elements and is an array so do something
                  

                  BTW, dont use $REQUEST unless you really have to. If the form is sent with post method, use $POST to check forms variables. If the form is sent with get method, use $_GET.

                  For the query modify it like this:

                  $question_ids = implode(',',$questionid);
                  $sql = "UPDATE ".$db->pre."quiz_questions SET enabled = 1 WHERE question_id IN ({$question_ids})";
                  

                  Now if there is some elements checked(lets say question with id 2,5,7 and 8) the query would turn out something like this:

                  UPDATE pre_quiz_questions SET enabled = 1 WHERE question_id IN (2,5,7,8);
                  
                    Write a Reply...