Jump to content

Help storing form values for questionnaire


mikrax

Recommended Posts

Hi

 

I am beginner in PHP and MYSQL and having trouble storing values for a questionnaire that i have to do as part of an appraisal system.

 

I have been able to output the questions from the database but do not know how to implement the part which requires me to make another php file that retrieves each answer from the radio button and stores them in a databse for a unique user. Im not sure where the userid of the person doing the questionnaire will be retrieved a as have not yet coded this. But my system needs to know whose doing the questionnaire and what asnwers they have seletced. Im really stuck, please help.

 

Below is the PHP code to output questions and radio button asnwers:

 

 

 

<?php

 

$con = mysql_connect("localhost","root","");

if (!$con)

  {

  die('Could not connect: ' . mysql_error());

 

 

 

// select database

}mysql_select_db("feedback") or die('ERROR: Unable to select database!');

 

// generate and execute query

$query = "SELECT qid, qtitle1 FROM questions";

$result = mysql_query($query) or die("ERROR: $query.".mysql_error());

 

// if records are present

if (mysql_num_rows($result) > 0) {

    $row = mysql_fetch_object($result);

 

 

$index = 1;

    // LOOP TO OUTPUT QUESTIONs

while ($row = mysql_fetch_object($result)) {  //LOOP OUTPUTTING EACH QUESTION

 

        // get question ID and title

$qid = $row->qid;

 

echo "<form method = post action = 'processanswers.php'>";

 

echo '<h4>'.$row->qtitle1 .'</h4>';

 

  // variable used to assign name to each group of radio buttons 

    $name = "answer".$index;

 

 

//output radio buttons, assigning value to each button, outputtin a different label for e

echo "<input type=\"radio\" name=$name value=4 \>";

    echo "<label>Strongly Agree <br/>";

 

echo "<input type=\"radio\" name=$name value=3 \>";

echo "<label>Agree <br/>";

 

echo "<input type=\"radio\" name=$name value=2 \>";

//echo $name;

echo "<label>Strongly Disagree <br/>";

 

echo "<input type=\"radio\" name=$name value=1 \>";

echo "<label>Disagree <br/>";

 

$index++;

} //end loop

 

echo "<input type = hidden name = qid value = '".$qid."'>\n";

echo "<br><input type = submit name = submit value = 'Submit'>\n\n";

 

echo '</form>';

 

}//Closes IF

 

// if no records present, display message

else {

    echo '<font size="-1">No questions currently configured</font>';

      }

?>

 

Relevant database tables below to understand my system structure

 

table.Appraisal

Appraisalid

Userid [fk]

Startdate

Expectedcompdate

 

table.Questions

Qid [pk]

Qtitle1

Qtitle2

Competency

 

table.Answers

Qid [fk]

Userid [fk]

Apprsaialid [fk]

Answer

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.