Hi all,

this is what I've built:
A dynamically built form which selects the questions depending on the section of the form it's in.

The problem:
Each form input is called answer[] passing the selected value to an update query

 $updateSQL = sprintf("UPDATE tblsite SET sitetypeid=%s, pctid=%s, contactname=%s, address=%s, postcode=%s, email=%s, phone=%s, sitename=%s WHERE siteid=%s",
  GetSQLValueString($_POST['sitetype'], "int"),
  GetSQLValueString($_POST['pct'], "int"),
  GetSQLValueString($_POST['contactname'], "text"),
  GetSQLValueString($_POST['siteaddress'], "text"),
  GetSQLValueString($_POST['postcode'], "text"),
  GetSQLValueString($_POST['email'], "text"),
  GetSQLValueString($_POST['contactphone'], "text"),
  GetSQLValueString($_POST['sitename'], "text"),
  GetSQLValueString($_SESSION['siteid'], "int"));

  mysql_select_db($database_auditing, $auditing);
  $Resultupdatesite = mysql_query($updateSQL, $auditing) or die(mysql_error());


$auditid = $_SESSION['auditid'];
$saved = "1";
$savemeonce = "True";
$siteaudit1 = $_SESSION['siteid'];
$answernum = $_POST['answerid']; 
$response =  $_POST['answer']; 


$num = count($_POST['answerid']); 
$numb = $num-1;

for ($q=0;$q<=$numb;$q++) 
{ 

    $auditnumber = $auditid; 
    $answer33 = $response[$q];
    $answerid = $answernum[$q];



$queryupdateanswer = sprintf("UPDATE tblanswer SET auditid = %s, answer = %s WHERE answerid = %s",
GetSQLValueString($auditnumber, "int"),
GetSQLValueString($answer33, "int"), 
GetSQLValueString($answerid, "int"));
  mysql_select_db($database_auditing, $auditing);
  $resultupdateanswer = mysql_query($queryupdateanswer, $auditing) or die(mysql_error());


}

The problem I've got is that the form builds itself by querying the database within each section to select the relevant questions. Because of the way these are selected the array key is reset to 0 within each form tab thus stopping the update loop above from working.

Can anyone suggest a way around this (or a better way to build the form - which has to stay in sections and needs to be dynamic).

The current form code:

<?php 
     while ($row_sections=mysql_fetch_assoc($sections)) {?>
  <div class="AccordionPanel">
    <div class="AccordionPanelTab"><?php echo $row_sections['sectionname'];?></div>
    <div class="AccordionPanelContent">
    <br />
    <h5>Please answer the questions below to the best of your ability. For help, hover over the help icon, help text will appear in the box to the right of the screen.</h5>
        <?php $questionsection = $row_sections['sectionid'];
mysql_select_db($database_auditing, $auditing);
$query_sections3 = sprintf("SELECT tblanswer.questionid AS answerqid, tblanswer.answerid AS answerid, tblanswer.answer AS answer, tblquestion.questionid AS questionid, tblquestion.questiontext AS questiontext, tblquestion.questionid AS quesid, tblquestion.questiontypeid AS questiontype, tblscore.score1 AS score1, tblscore.score2 AS score2, tblscore.score3 AS score3, tblscore.score3 AS score3, tblscore.score4 AS score4, tblhelptext.helptext AS help FROM tblanswer LEFT JOIN tblquestion ON tblanswer.questionid = tblquestion.questionid LEFT JOIN tblscore ON tblquestion.questionid = tblscore.questionid LEFT JOIN tblhelptext ON tblquestion.questionid = tblhelptext.questionid WHERE tblquestion.sectionid = %s AND tblanswer.auditid=%s ",  
GetSQLValueString($questionsection, "int"),
GetSQLValueString($_SESSION['auditid'], "int"));

$sections3 = mysql_query($query_sections3, $auditing) or die(mysql_error());
$row_sections3=mysql_fetch_assoc($sections3);
$totalRows_sections3 = mysql_num_rows($sections3);      

?>

<table class="table2" align="center">
<?php $purpleronnie=0; do {  
?><tr>

<th><?php echo $row_sections3['questiontext'];?> <input type="hidden" name="qnumber[]" value="<?php echo $row_sections3['questionid'];?>" />
</th>
<td>
<input type="hidden" name="answerid[]" value="<?php echo $row_sections3['answerid'];?>" />
<?php if ($row_sections3['questiontype']=="1") { ?> 
<input type="text" size="25" name="answer[]" value="<?php echo $row_sections3['answer'];?>" />

 <?php } 
    else if ($row_sections3['questiontype']=="2") {?> 

    Yes: <input type="radio" name="answer[<?php echo $purpleronnie;?>]" value="<?php echo $row_sections3['score1'];?>" <?php if (!(strcmp(htmlentities($row_sections3['score1'], ENT_COMPAT, 'utf-8'),$row_sections3['answer']))) {echo "checked=\"checked\"";} ?>/> 

    No:<input type="radio" name="answer[<?php echo $purpleronnie;?>]" value="<?php $row_sections3['score2'];?>" <?php if (!(strcmp(htmlentities($row_sections3['answer'], ENT_COMPAT, 'utf-8'),$row_sections3['score2']))) {echo "checked=\"checked\"";} ?>/><?php }  

     else if ($row_sections3['questiontype']=="3") {?> 

     All: <input type="radio" name="answer<?php echo $questionsection;?>[<?php echo $purpleronnie;?>]" value="<?php $row_sections3['score1'];?>" <?php if (!(strcmp(htmlentities($row_sections3['answer'], ENT_COMPAT, 'utf-8'),$row_sections3['score1']))) {echo "checked=\"checked\"";} ?>/> 

     Some: <input type="radio" name="answer[<?php echo $purpleronnie;?>]" value="<?php $row_sections3['score2'];?>" <?php if (!(strcmp(htmlentities($row_sections3['answer'], ENT_COMPAT, 'utf-8'),$row_sections3['score2']))) {echo "checked=\"checked\"";} ?>/> 

     None: <input type="radio" name="answer[<?php echo $purpleronnie;?>]" value="<?php $row_sections3['score3'];?>" <?php if (!(strcmp(htmlentities($row_sections3['answer'], ENT_COMPAT, 'utf-8'),$row_sections3['score3']))) {echo "checked=\"checked\"";} ?>/> <?php }  

      else if ($row_sections3['questiontype']=="4") {?> 

      <input type="checkbox" name="answer[]" value="<?php $row_sections3['score1'];?>" <?php if (!(strcmp($row_sections3['answer'],$row_sections3['score1']))) {echo "checked=\"checked\"";} ?>/><?php }

       else if ($row_sections3['questiontype']=="5") {?> 

       <input type="text" name="answer[]" value="<?php echo $row_sections3['answer'];?>" size="3"/><?php }

        else if ($row_sections3['questiontype']=="6") {?> 

        <input type="date" name="answer[]" value="<?php $row_sections3['answer'];?>" size="25"/><?php }

         else if ($row_sections3['questiontype']=="7") { 

          $currentq = $row_sections3['questionid'];

 mysql_select_db($database_auditing, $auditing);
$query_lists = sprintf("SELECT optioning, optionscore FROM tbllistoptions WHERE questionid = %s", GetSQLValueString($currentq, "int"));

$lists = mysql_query($query_lists, $auditing) or die(mysql_error());
$row_lists = mysql_fetch_assoc($lists);
$totalRows_lists = mysql_num_rows($lists);

?> 
<select name="answer[]"><option value="0" <?php if (!(strcmp($row_sections3['answer'], ""))) {echo "selected=\"selected\"";} ?>>Please Select....</option>
<?php
do {  ?>

      <option value="<?php echo $row_lists['optionscore']?>"<?php if (!(strcmp($row_sections3['answer'], $row_lists['optionscore']))) {echo "selected=\"selected\"";} ?>><?php echo $row_lists['optioning'];?></option>
       <?php
} while ($row_lists = mysql_fetch_assoc($lists));
  $rows = mysql_num_rows($lists);
  if($rows > 0) {
      mysql_data_seek($lists, 0);
      $row_lists = mysql_fetch_assoc($lists);
  }
?>

</select><?php }
          else if ($row_sections3['questiontype']=="8") {?> <textarea name="answer[]" cols="40" rows="5"><?php echo $row_sections3['answer'];?></textarea><?php } ?></td>

<td><a class="info" href="#"><img src="../images/question.png" class="img" longdesc=""  onmouseover="MM_setTextOfTextfield('helptext','','<?php echo $row_sections3['help'];?>')" style="cursor:help;" /></a></td>
</tr>
<?php $purpleronnie++;
} 

while($row_sections3=mysql_fetch_assoc($sections3));?>
</table>



    </div>
  </div>

  <?php  }?>

  <input type="hidden" name="firsttime" value="<?php echo $row_saved['firstsave'];?>"  /> <p>&nbsp;</p>
 </div>

</form>

Thanks in advance!
Dave

Recommended Answers

All 2 Replies

Do you have this code online where I can look at the source. Due to formatting issues, the code you posted is very hard to read, which is making it hard to help solve the problem. As an alternative, could you attach the source code?

Hi kkeith, sorry about the formatting. The code is still being developed offline so I'll try and re-post it here with better formatting (tried to upload it but couldn't get it to attach).

<?php require_once('../Connections/auditing.php');

if (!isset($_SESSION)) {
  session_start();
}


if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $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;
}
}


$updateSQL = sprintf("UPDATE tblsite SET sitetypeid=%s, pctid=%s, contactname=%s,
  address=%s, postcode=%s, email=%s, phone=%s, sitename=%s WHERE siteid=%s",
  GetSQLValueString($_POST['sitetype'], "int"),
  GetSQLValueString($_POST['pct'], "int"),
  GetSQLValueString($_POST['contactname'], "text"),
  GetSQLValueString($_POST['siteaddress'], "text"),
  GetSQLValueString($_POST['postcode'], "text"),
  GetSQLValueString($_POST['email'], "text"),
  GetSQLValueString($_POST['contactphone'], "text"),
  GetSQLValueString($_POST['sitename'], "text"),
  GetSQLValueString($_SESSION['siteid'], "int"));

  mysql_select_db($database_auditing, $auditing);
  $Resultupdatesite = mysql_query($updateSQL, $auditing) or die(mysql_error());


$auditid = $_SESSION['auditid'];
$saved = "1";
$savemeonce = "True";
$siteaudit1 = $_SESSION['siteid'];
$answernum = $_POST['answerid']; 
$response =  $_POST['answer']; 


$num = count($_POST['answerid']); 
$numb = $num-1;

for ($q=0;$q<=$numb;$q++) 
{ 

    $auditnumber = $auditid; 
    $answer33 = $response[$q];
    $answerid = $answernum[$q];



$queryupdateanswer = sprintf("UPDATE tblanswer SET auditid = %s, answer = %s 
WHERE answerid = %s",

GetSQLValueString($auditnumber, "int"),
GetSQLValueString($answer33, "int"), 
GetSQLValueString($answerid, "int"));

mysql_select_db($database_auditing, $auditing);
  $resultupdateanswer = mysql_query($queryupdateanswer, $auditing) or die(mysql_error());


}




      header("Location: auditingquestionnaire.php" );

?>

And the questionnaire page:

<?php require_once('../Connections/auditing.php'); 
if (!isset($_SESSION)) {
  session_start();
}


if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $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;
}
}


$auditid = $_SESSION['auditnumber'];
$current = "True";
$formaction = "auditinganswerinput.php";


$colname_sitedetails = "-1";
if (isset($_SESSION['siteid'])) {
  $colname_sitedetails = $_SESSION['siteid'];
}

mysql_select_db($database_auditing, $auditing);

$query_sitedetails = sprintf("SELECT siteid, sitetypeid, pctid, 
contactname, address, postcode, email, phone, sitename 

FROM tblsite 
WHERE siteid = %s", 
GetSQLValueString($colname_sitedetails, "int"));

$sitedetails = mysql_query($query_sitedetails, $auditing) or die(mysql_error());
$row_sitedetails = mysql_fetch_assoc($sitedetails);
$totalRows_sitedetails = mysql_num_rows($sitedetails);


mysql_select_db($database_auditing, $auditing);

$query_sections = sprintf("SELECT sectionid, sectionname FROM tblsection 
WHERE current = %s", GetSQLValueString($current, "text"));

$sections = mysql_query($query_sections, $auditing) or die(mysql_error());
$totalRows_sections = mysql_num_rows($sections);


mysql_select_db($database_auditing, $auditing);

$query_sections2 = sprintf("SELECT sectionid, sectionname 

FROM tblsection 
WHERE current = %s", GetSQLValueString($current, "text"));

$sections2 = mysql_query($query_sections2, $auditing) or die(mysql_error());
$totalRows_sections2 = mysql_num_rows($sections2);


$relevant = "True";


mysql_select_db($database_auditing, $auditing);

$query_saved = sprintf("SELECT firstsave FROM tblaudit WHERE auditid = %s",
GetSQLValueString($auditid, "int"));

$saved = mysql_query($query_saved, $auditing) or die(mysql_error());
$row_saved = mysql_fetch_assoc($saved);
$totalRows_saved = mysql_num_rows($saved);


mysql_select_db($database_auditing, $auditing);

$query_pct = "SELECT pctid, pctname FROM tblpct ";

$pct = mysql_query($query_pct, $auditing) or die(mysql_error());
$row_pct = mysql_fetch_assoc($pct);
$totalRows_pct = mysql_num_rows($pct);


mysql_select_db($database_auditing, $auditing);

$query_sitetype = "SELECT sitetypeid, sitetype FROM tblsitetype";

$sitetype = mysql_query($query_sitetype, $auditing) or die(mysql_error());
$row_sitetype = mysql_fetch_assoc($sitetype);
$totalRows_sitetype = mysql_num_rows($sitetype);


mysql_select_db($database_auditing, $auditing);
$query_previous = sprintf("SELECT tblaudit.auditid, tblaudit.auditorid, 
tblaudit.datetime, tblaudit.time, tblaudit.noncompliant, tblaudit.reason, 
tblauditor.name 

FROM tblaudit 
LEFT JOIN tblauditor ON tblaudit.auditorid = tblaudit.auditid 

WHERE tblaudit.siteid = %s ORDER BY tblaudit.audityear",
GetSQLValueString($colname_sitedetails, "int"));

$previous = mysql_query($query_previous, $auditing) or die(mysql_error());
$row_previous = mysql_fetch_assoc($previous);
$totalRows_previous = mysql_num_rows($previous);



?>
<!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>Auditing Questionnaire</title>
<link href="../CSS/stylesheet2.css" rel="stylesheet" type="text/css" />

<script src="../SpryAssets/SpryAccordion.js" type="text/javascript"></script>
<script src="../SpryAssets/scrollerjs.js" type="text/javascript"></script>

<link href="../SpryAssets/SpryAccordion.css" rel="stylesheet" type="text/css" />
<script type="text/javascript">
function MM_setTextOfTextfield(objId,x,newText) { //v9.0
  with (document){ if (getElementById){
    var obj = getElementById(objId);} if (obj) obj.value = newText;
  }
}
function MM_showHideLayers() { //v9.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) 
  with (document) if (getElementById && ((obj=getElementById(args[i]))!=null)) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}
</script>
</head>

<body>

<div class="container">

  <div class="header">

    <div class="essentialogo"></div>

    <div class="gsttlogo"></div>

  </div>
<div class="content">


 <div class="fltrt">

<div id="tablefloat">

  <table class="table2" align="center" id="savetable" >   
<tr>
   <td colspan="2" align="center"><h5>Help Text</h5></td>
   </tr>
   <tr>
   <td colspan="2" align="center"><textarea name="helptext" cols="20" rows="5" id="helptext"> 
   </textarea></td>
   </tr>
   <tr>

   <td colspan="2"><h5 align="center">Save and Submit</h5></td>
</tr>
<tr>
<th colspan="2">Please use the buttons below<br /> to save or submit your audit</th>
</tr>
<tr>
<td align="center"><input type="button" name="saveit" value="Save" 
style="width:75px; height:35px; font-weight:bolder;"  
onclick="document.theform.submit()"/></td>

<td align="center"><input type="button" name="submitit" value="Submit" 
style="width:75px; height:35px;font-weight:bolder;" 
onclick="document.theform.submit()"/></td>
</tr>
</table>
</div>
 </div>

 <div class="fltlft">

<h2 align="center">Audit Questionnaire</h2>

<br />

<h5>Please answer the questions in each section shown below 
(clicking on the section title will show the questions).</h5>

<p>The questionnaire can be saved at any time by clicking the save button to the right, 
once completed please click the submit button to see your audit report. 
Once submitted, no more changes can be made.</p>
<br/>

<form method="post" action="<?php echo $formaction;?>" name="theform" id="theform">

<div id="Accordion1" class="Accordion" tabindex="0">

<div class="AccordionPanel">

<div class="AccordionPanelTab">Site Details and Previous Audits</div>

<div class="AccordionPanelContent">
 <br />

<h5>Please update your site details</h5>

<br />

<table class="table2" align="center">

<tr>
<th>Site Type:</th>
<td><select name="sitetype"><option value="" 
<?php if (!(strcmp($row_sitetype['sitetypeid'],""))) 
{ echo "selected=\"selected\"";}?>>Please Select.....</option>

<?php do {?>

<option value="<?php echo $row_sitetype['sitetypeid'];?>" 
<?php if (!(strcmp($row_sitetype['sitetypeid'],$row_sitedetails['sitetypeid']))) 
{ echo "selected=\"selected\"";}?>><?php echo $row_sitetype['sitetype'];?></option>



<?php } while ($row_sitetype=mysql_fetch_assoc($sitetype)); 

$rows1 = mysql_num_rows($sitetype);
  if($rows1 > 0) {
      mysql_data_seek($sitetype, 0);
      $row_sitetype = mysql_fetch_assoc($sitetype);
  }?>
</select>
</td>
</tr>

  <tr>
<th>Site Name:</th>

<td><input type="text" name="sitename" 
value="<?php echo $row_sitedetails['sitename']; ?>" size="35" /></td>
</tr>

<tr>

<th>Site Address:</th>
<td><input type="text" name="siteaddress" size="35" 
value="<?php echo $row_sitedetails['address'];?>" /></td> 
</tr>
<tr>

<th>Postcode:</th>
<td><input type="text" name="postcode" 
value="<?php echo $row_sitedetails['postcode']; ?>" size="25" /></td>
</tr>

<tr>
<th>Contact Name:</th>
<td><input type="text" name="contactname" 
value="<?php echo $row_sitedetails['contactname']; ?>" size="35" /></td>
</tr>

<tr>

<th>Email Address:</th>

<td><input type="text" name="email" 
value="<?php echo $row_sitedetails['email']; ?>" size="35" /></td>
</tr>

<tr>

<th>Phone Number:</th>

<td><input type="text" name="contactphone" 
value="<?php echo $row_sitedetails['phone']; ?>" size="35" /></td>
</tr>
<tr>

<th>PCT:</th>

<td><select name="pct"><option value="" <?php if (!(strcmp($row_pct['pctid'],""))) 
{ echo "selected=\"selected\"";}?>>Please Select.....</option>

<?php do {?>
    <option value="<?php echo $row_pct['pctid'];?>" 
    <?php if (!(strcmp($row_pct['pctid'],$row_sitedetails['pctid']))) 
    { echo "selected=\"selected\"";}?>><?php echo $row_pct['pctname'];?></option>



<?php } while ($row_pct=mysql_fetch_assoc($pct)); 
$rows2 = mysql_num_rows($pct);
  if($rows2 > 0) {
      mysql_data_seek($pct, 0);
      $row_pct = mysql_fetch_assoc($pct);
  }?>
</select>
</td>
</tr>

<tr>
<th colspan="2" align="center">Previous Audits</th>
</tr>

<?php do {?>

<tr>
<td><?php echo $row_previous['datetime'].", ".$row_previous['time'];?></td>
<td><a href="../auditreporting/auditingreport.php?site=<?php echo $colname_sitedetails;?>
&audit=<?php echo $row_previous['auditid'];?>">View</a></td>
</tr>

<?php }while ($row_previous=mysql_fetch_assoc($previous));?>

</table>

<br />

</div>
</div>

<!---Build the questionnaire tabs--->
<?php 
     while ($row_sections=mysql_fetch_assoc($sections)) {?>

  <div class="AccordionPanel">
    <div class="AccordionPanelTab">

    <?php echo $row_sections['sectionname'];?>
    </div>

    <div class="AccordionPanelContent">

  <br />

  <h5>Please answer the questions below to the best of your ability. 
  For help, hover over the help icon, help text will appear in the box 
  to the right of the screen.</h5>

<!---Select the questions relevant to each section--->

<?php $questionsection = $row_sections['sectionid'];

mysql_select_db($database_auditing, $auditing);

$query_sections3 = sprintf("SELECT tblanswer.questionid AS answerqid, 
tblanswer.answerid AS answerid, tblanswer.answer AS answer, 
tblquestion.questionid AS questionid, tblquestion.questiontext AS questiontext, 
tblquestion.questionid AS quesid, tblquestion.questiontypeid AS questiontype, 
tblscore.score1 AS score1, tblscore.score2 AS score2, tblscore.score3 AS score3, 
tblscore.score3 AS score3, tblscore.score4 AS score4, 
tblhelptext.helptext AS help 

FROM tblanswer LEFT JOIN tblquestion ON tblanswer.questionid = tblquestion.questionid 
               LEFT JOIN tblscore ON tblquestion.questionid = tblscore.questionid 
               LEFT JOIN tblhelptext ON tblquestion.questionid = tblhelptext.questionid 

               WHERE tblquestion.sectionid = %s AND tblanswer.auditid=%s ",  

GetSQLValueString($questionsection, "int"),
GetSQLValueString($_SESSION['auditid'], "int"));

$sections3 = mysql_query($query_sections3, $auditing) or die(mysql_error());
$row_sections3=mysql_fetch_assoc($sections3);
$totalRows_sections3 = mysql_num_rows($sections3);      

?>

<!---Show the questions in a table built by the query above--->
<table class="table2" align="center">

<?php $purpleronnie=0; 
do {  

?><tr>

<!---input types are selected and displayed depending on the type of question required--->

<th><?php echo $row_sections3['questiontext'];?> <input type="hidden" name="qnumber[]" 
value="<?php echo $row_sections3['questionid'];?>" />
</th>

<td>

<input type="hidden" name="answerid[]" value="<?php echo $row_sections3['answerid'];?>" />

<?php if ($row_sections3['questiontype']=="1") { ?> 

<input type="text" size="25" name="answer[]" value="<?php echo $row_sections3['answer'];?>" />

 <?php } 

    else if ($row_sections3['questiontype']=="2") {?> 

    Yes: <input type="radio" name="answer[<?php echo $purpleronnie;?>]" 
    value="<?php echo $row_sections3['score1'];?>" 
    <?php if (!(strcmp(htmlentities($row_sections3['score1'], ENT_COMPAT, 'utf-8'),
    $row_sections3['answer']))) 
    {echo "checked=\"checked\"";} ?>/> 

    No:<input type="radio" name="answer[<?php echo $purpleronnie;?>]" 
    value="<?php $row_sections3['score2'];?>" 
    <?php if (!(strcmp(htmlentities($row_sections3['answer'], ENT_COMPAT, 'utf-8'),
    $row_sections3['score2']))) 
    {echo "checked=\"checked\"";} ?>/><?php }  


     else if ($row_sections3['questiontype']=="3") {?> 

     All: <input type="radio" name="answer[<?php echo $purpleronnie;?>]" 
     value="<?php $row_sections3['score1'];?>" 
     <?php if (!(strcmp(htmlentities($row_sections3['answer'], ENT_COMPAT, 'utf-8'),
     $row_sections3['score1']))) {echo "checked=\"checked\"";} ?>/> 

     Some: <input type="radio" name="answer[<?php echo $purpleronnie;?>]" 
     value="<?php $row_sections3['score2'];?>" 
     <?php if (!(strcmp(htmlentities($row_sections3['answer'], ENT_COMPAT, 'utf-8'),
     $row_sections3['score2']))) {echo "checked=\"checked\"";} ?>/> 

     None: <input type="radio" name="answer[<?php echo $purpleronnie;?>]" 
     value="<?php $row_sections3['score3'];?>" 
     <?php if (!(strcmp(htmlentities($row_sections3['answer'], ENT_COMPAT, 'utf-8'),
     $row_sections3['score3']))) {echo "checked=\"checked\"";} ?>/> 

     <?php }  

      else if ($row_sections3['questiontype']=="4") {?> 

      <input type="checkbox" name="answer[]" value="<?php $row_sections3['score1'];?>" 
      <?php if (!(strcmp($row_sections3['answer'],
      $row_sections3['score1']))) {echo "checked=\"checked\"";} ?>/>

      <?php }

       else if ($row_sections3['questiontype']=="5") {?> 

       <input type="text" name="answer[]" value="<?php echo $row_sections3['answer'];?>" 
       size="3"/>

       <?php }

        else if ($row_sections3['questiontype']=="6") {?> 

        <input type="date" name="answer[]" value="<?php $row_sections3['answer'];?>" size="25"/>

    <!---If the question is a select box, build the input--->

      <?php }

         else if ($row_sections3['questiontype']=="7") { 

          $currentq = $row_sections3['questionid'];

      mysql_select_db($database_auditing, $auditing);
      $query_lists = sprintf("SELECT optioning, optionscore FROM tbllistoptions 
      WHERE questionid = %s", 
      GetSQLValueString($currentq, "int"));

     $lists = mysql_query($query_lists, $auditing) or die(mysql_error());
     $row_lists = mysql_fetch_assoc($lists);
     $totalRows_lists = mysql_num_rows($lists);

     ?>

   <select name="answer[]"><option value="0" <?php if (!(strcmp($row_sections3['answer'], ""))) 
    {echo "selected=\"selected\"";} ?>>Please Select....</option>
    <?php
    do {  ?>

      <option value="<?php echo $row_lists['optionscore']?>"
      <?php if (!(strcmp($row_sections3['answer'], $row_lists['optionscore']))) 
      {echo "selected=\"selected\"";} ?>><?php echo $row_lists['optioning'];?></option>
       <?php

     } while ($row_lists = mysql_fetch_assoc($lists));
     $rows = mysql_num_rows($lists);
     if($rows > 0) {
      mysql_data_seek($lists, 0);
      $row_lists = mysql_fetch_assoc($lists);
  }
  ?>

  </select><?php }

          else if ($row_sections3['questiontype']=="8") {?> 

<textarea name="answer[]" cols="40" rows="5"><?php echo $row_sections3['answer'];?></textarea>

 <?php } ?></td>

<!---Set help text in help text box--->

<td><a class="info" href="#">
<img src="../images/question.png" class="img" longdesc=""  
onmouseover="MM_setTextOfTextfield('helptext','','<?php echo $row_sections3['help'];?>')" 
style="cursor:help;" /></a></td>
</tr>
<?php $purpleronnie++;
} 

while($row_sections3=mysql_fetch_assoc($sections3));?>
<!---Thats the questionnaire built, close the table then end the section--->
</table>



    </div>
  </div>

  <?php  }?>

<!---End of questionnaire--->

  <input type="hidden" name="firsttime" 
  value="<?php echo $row_saved['firstsave'];?>"  /> <p>&nbsp;</p>
 </div>

</form>
</div>

<!-- end .content --></div>
  <div class="footer">
    <h6><?php echo $_SESSION['auditid'];?>
    <?php echo $_SESSION['selfauditno'];?>
    <?php echo $_SESSION['siteid'];?></h6>
    <!-- end .footer --></div>
  <!-- end .container --></div>


<script type="text/javascript">
var Accordion1 = new Spry.Widget.Accordion("Accordion1");
</script>
</body>
</html>
<?php 
mysql_free_result($sitedetails);
mysql_free_result($pct);
mysql_free_result($sitetype);

?>

Thanks again!
Dave

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.