Radiobuttons (groups) and PHP

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Energetic Pixels
Forum Newbie
Posts: 1
Joined: Wed Oct 07, 2009 12:22 pm
Location: Oklahoma / USA
Contact:

Radiobuttons (groups) and PHP

Post by Energetic Pixels »

Ok. I fixed most of my problems yesterday evening. But I uncovered
another one. In my attached code, is there a way to get each row
of radio buttons to act as their own instance (apart from the next
row)??? The way that I have the code now is that php is dynamically
generating the next row in the table until it runs out of data coming
back from mysql.

Other problem will be dealing with how to get the user inputted data
out of all the tables and submit them to the database all the while
correlating them to the user_ID and quest_ID. But I can tackle that
once I get the radio buttons to act correctly.

Tony :?

Code: Select all

 
<?php require_once('Connections/userSubmitComments.php'); ?>
 
<?php
    if (!function_exists("GetSQLValueString")) {
        function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") {
            $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
            $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : 
 
mysql_escape_string($theValue);
            switch ($theType) {
                case "text":
                $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
                break;    
                case "long":
                case "int":
                $theValue = ($theValue != "") ? intval($theValue) : "NULL";
                break;
                case "double":
                $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
                break;
                case "date":
                $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
                break;
                case "defined":
                $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
                break;
            }
        return $theValue;
        }
    }
 
    $editFormAction = $_SERVER['PHP_SELF'];
    if (isset($_SERVER['QUERY_STRING'])) {
        $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
    }
 
    if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "ParticipantInformatoin")) {
        $insertSQL = sprintf("INSERT INTO participant (employer, `position`, militaryBranch) VALUES (%s, %s, %s)",          
 
GetSQLValueString($_POST['employer'], "text"),
            GetSQLValueString($_POST['position'], "text"),
            GetSQLValueString($_POST['militaryBranch'], "text"));
 
    mysql_select_db($database_userSubmitComments, $userSubmitComments);
    $Result1 = mysql_query($insertSQL, $userSubmitComments) or die(mysql_error());
}
 
mysql_select_db($database_userSubmitComments, $userSubmitComments);
$query_submitUserInfo = "SELECT participant.employer, participant.`position`, participant.militaryBranch FROM participant";
$submitUserInfo = mysql_query($query_submitUserInfo, $userSubmitComments) or die(mysql_error());
$row_submitUserInfo = mysql_fetch_assoc($submitUserInfo);
$totalRows_submitUserInfo = mysql_num_rows($submitUserInfo);
 
mysql_select_db($database_userSubmitComments, $userSubmitComments);
$query_designQuestions = "SELECT squestions.question FROM squestions WHERE squestions.group_ID = 1";
$designQuestions = mysql_query($query_designQuestions, $userSubmitComments) or die(mysql_error());
$row_designQuestions = mysql_fetch_assoc($designQuestions);
$totalRows_designQuestions = mysql_num_rows($designQuestions);
 
mysql_select_db($database_userSubmitComments, $userSubmitComments);
$query_useQuestions = "SELECT squestions.question FROM squestions WHERE squestions.group_ID = 2";
$useQuestions = mysql_query($query_useQuestions, $userSubmitComments) or die(mysql_error());
$row_useQuestions = mysql_fetch_assoc($useQuestions);
$totalRows_useQuestions = mysql_num_rows($useQuestions);
 
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Community of Practice User Survey</title>
 
<style type=text/css>
.textRotation {
left:2px; top:2px;
width:25px; writing-mode: tb-rl;
}
</style>
 
</head>
<body>
    <p>Thank you for taking the time to let us know your thoughts about this community. Out oal is to make this site work for you! We 
 
will use your input as we look to add information and create future improvements to the Ammunition Community of Practice</p>
<p>The first three designQuestions ask you to provide information about yourself. After that, please complete the rest of the survey by 
 
reading ech statement and clicking the appropriate response.</p>
    <p>We want this CoP to help you so we need you to help us make it better. Please provide any specific suggestions on how we can 
 
improve an area of the site that you found less than "helpful".</p>
<p>Thanks for your time and participation in making the <strong>Ammunition Community of Practice</strong> THE place to go!</p>
 
<!--      *** THE IMMEDIATE FORM BELOW IS FOR USER DEMOGRAPHICS.  DO NOT MODIFY.  IT WORKS JUST FINE  ***** -->
<form action="<?php echo $editFormAction; ?>" method="POST" name="ParticipantInformatoin" id="participant">
    <p>
        <label for="employer">Are you military, DoD Civilian, DoD Contractor or other?</label><input name="employer" type="text" 
 
id="employer" value="" />
      </p>
      <p>
        <label for="position">What is your rank or position?</label>
        <input name="position" type="text" id="position" />
      </p>
      <p>
        <label for="militaryBranch">If you are military, what is your branch of service?</label>
        <input name="militaryBranch" type="text" id="militaryBranch" />
      </p>
      <!--<p>
        <input name="yourComments" type="submit" id="yourComments" value="Send your name" />
      </p> -->
        
    <input type="hidden" name="MM_insert" value="ParticipantInformatoin" />
</form>
 
 
<form action="" method="post" name="design" target="_self">
    <table width="750" border="1" bordercolor="#FF0000">
    <tr>
        <th scope="col" valign="top"><div align="left">Design of the Ammunition Forum</div></th>
        <th class="textRotation" scope="col">Not at all helpful</th>
        <th class="textRotation" scope="col">Not very helpful</th>
        <th class="textRotation" scope="col">Somewhat helpful</th>
        <th class="textRotation" scope="col">Helpful</th>
        <th class="textRotation" scope="col">Very Helpful</th>
        <th class="textRotation" scope="col">Don't Apply</th>
    </tr>
    <?php do { ?>
        <tr>
            <td><?php echo $row_designQuestions['question']; ?></td>
            <td><input type="radio" name="designRadio" value="1" id="ratingRadios" /></td>
            <td><input type="radio" name="designRadio" value="2" id="ratingRadios" /></td>
            <td><input type="radio" name="designRadio" value="3" id="ratingRadios" /></td>
            <td><input type="radio" name="designRadio" value="4" id="ratingRadios" /></td>
            <td><input type="radio" name="designRadio" value="5" id="ratingRadios" /></td>
            <td><input type="radio" name="designRadio" value="0" id="ratingRadios" /></td>
        </tr>
        <?php } while ($row_designQuestions = mysql_fetch_assoc($designQuestions)); ?>
        </table>
    </form>
    
<form action="" method="post" name="use" target="_self">
        <table width="750" border="1" bordercolor="#FF0000">
        <tr>
            <th scope="col" valign="top"><div align="left">Use of the Ammunition Forum</div></th>
            <th class="textRotation" scope="col">Not as yet</th>
            <th class="textRotation" scope="col">Only once</th>
            <th class="textRotation" scope="col">A few times</th>
            <th class="textRotation" scope="col">Many times</th>
            <th class="textRotation" scope="col">Quite frequently</th>
        </tr>
        <?php do { ?>
        <tr>
            <td><?php echo $row_useQuestions['question']; ?></td>
            <td><input type="radio" name="useRadio" value="0" id="ratingRadios" /></td>
            <td><input type="radio" name="useRadio" value="1" id="ratingRadios" /></td>
            <td><input type="radio" name="useRadio" value="2" id="ratingRadios" /></td>
            <td><input type="radio" name="useRadio" value="3" id="ratingRadios" /></td>
            <td><input type="radio" name="useRadio" value="4" id="ratingRadios" /></td>
        </tr>
        <?php } while ($row_useQuestions = mysql_fetch_assoc($useQuestions)); ?>
        </table>
    </form>
    
    <form id="freeformInput">
        <table width="750">
        <tr>
            <td>
                <p style="font-weight: bold">Please enter your comments in the provided text boxes.</p>
            </td>
        </tr>
        <tr>
            <td>
                <p>How did you learn about the Ammunition Community of Practice?
                <textarea cols="80" rows="5"></textarea></p>
            </td>
        </tr>
        <tr>
            <td>
                <p>What did you like most about the Ammunition Community of Practice?
                <textarea cols="80" rows="5"></textarea></p>
            </td>
        </tr>
        <tr>
            <td>
                <p>What did you like least about the Ammunition Community of Practice?
                <textarea cols="80" rows="5"></textarea></p>
            </td>
        </tr>
        <tr>
            <td>
                <p>Would you recommend the Ammunition Community of Practice to others?
                <textarea cols="80" rows="5"></textarea></p>
            </td>
        </tr>
        <tr>
            <td>
                <p>Additional comments:
                <textarea cols="80" rows="7"></textarea></p>
            </td>
        </tr>
        </table>
    </form>
        
    
</body>
</html>
<?php
mysql_free_result($submitUserInfo);
mysql_free_result($designQuestions);
mysql_free_result($useQuestions);
?>
 
Last edited by califdon on Wed Oct 07, 2009 2:55 pm, edited 1 time in total.
Reason: Changed code=Text to code=PHP in BBcode tags, to display syntax highlighting. Please note and format future postings accordingly.
robnet
Forum Commoner
Posts: 85
Joined: Mon Aug 10, 2009 8:32 am
Location: South East, UK

Re: Radiobuttons (groups) and PHP

Post by robnet »

Do you mean you want to be able to select no more than 1 radio button on each row?

You'll need to have a different name tag for each group of these radio buttons.
This post pretty much describes it, but you'll need to change the type etc: viewtopic.php?p=570894#p570894
Post Reply