patelp7 Posted March 21, 2007 Share Posted March 21, 2007 Hi I am doing a Project that i am working on which is based on creating a web-based 360 appraisal system. Its based around multiple individuals providing feedback through answering a questionnaire on the appraisee. Im currently working on the questionanire and have got the questions outputting from the database with the standard radio buttons being outputted. I need to be able to store the answers (the value) from the selected radio buttons to be stored for each user that is completes the questionnaire, this then has to be stored in the database somehow to be later used for perfroming calculations from which averages can be calculated once other individuals have completed their qauestionnaire. I think i need to store the value into an array before inputting it into the database. is this right? Also is there an easy way in which I can output the value of aselected radio button. Below is the code i have developed so far; which outputs the questions and answers. <html> <head><basefont face = 'Arial'></head> <body> <?php $con = mysql_connect("localhost","root",""); if (!$con) { die('Could not connect: ' . mysql_error()); /* // include configuration file include('config.php'); // open database connection $connection = mysql_connect($host, $user, $pass) or die('ERROR: Unable to connect!'); */ // select database }mysql_select_db("feedback") or die('ERROR: Unable to select database!'); // TASKS....need to store answers - format q page // 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 '<h4>'.$row->qtitle1 .'</h4>'; echo "<form method = post action = 'user_submit.php'>"; // 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 $name; echo "<label>Strongly Agree <br/>"; echo "<input type=\"radio\" name=$name value=3 \>"; echo $name; 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 $name; echo "<label>Disagree <br/>"; $index++; } //CLOSES IF echo "<input type = hidden name = qid value = '".$qid."'>\n"; echo "<input type = submit name = submit value = 'Vote!'>\n\n"; //for ($i = 1; $i < 10; $i++) { // echo "answer$i\n"; //} echo '</form>'; }//Closes 1st IF // if no records present, display message else { echo '<font size="-1">No questions currently configured</font>'; } // close connection //mysql_close($connection); ?> </body> </html> Link to comment https://forums.phpfreaks.com/topic/43596-project-help-for-beginner-in-php-and-mysql-help-in-questionnaires/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.