Jump to content

Help with creating a survey function..


richarro1234

Recommended Posts

Hey there,

 

im trying to code a "create a survey" page, where users can make surveys with at least one section.

Each section must have at least 1 question, questions can have X amount of answers which the user can choose how many and the type of answers (i.e multiple choice, yes/no, likert scale, text box etc....)

 

I have got as far as having a question input, but not sure how to enable the user to choose the different select options for the answers and the amount of answers and input the answers and publish the survey.

 

Thanks

Rich

Link to comment
Share on other sites

well im using php for the code.

 

Here is the page i have so far, if someone wants to butcher it for me to SHOW me how to do it, as im not sure where to begin changing.

 

<?
include("data.php");
//include("funktioner.php");
mysql_connect($server,$dbuser,$dbpass);
mysql_select_db($database);
$query = mysql_query("SELECT * from users WHERE username = '".$_COOKIE["twusername"]."'") or die ('Error: '.mysql_error ());
while ($r = mysql_fetch_array($query)) {
$userid = $r['userid'];
}

if ($_GET['action'] == 'post') {

$month = date('n');
$day = date('d');
$year = date('Y');

$a1 = $_GET['a1'];
$a2 = $_GET['a2'];
$a3 = $_GET['a3'];
$a4 = $_GET['a4'];
$a5 = $_GET['a5'];
$a6 = $_GET['a6'];
$ownerid =  $_GET['userid'];

if ($_POST['question'] == '') {
header ("Location: addpoll.php?error=1");
die();
}


if ($_COOKIE['twusername'] == 'sk8nguitar') {
$name = "JD";
} elseif ($_COOKIE['twusername'] == 'richarro123') {
$name = "Rich";
} else {
$name = "?";
}

include("data.php");
mysql_connect($server,$dbuser,$dbpass);
mysql_select_db($databas);
mysql_query("INSERT INTO survey (squestion, publishdate, expdate, ownerid, active) VALUES ('" . $_POST['question']. "','$month/$day/$year','" . $_POST['expdate']. "','" . $_POST['userid']. "','yes')") or exit( mysql_error() );

mysql_query("INSERT INTO pchoices (a1, a2, a3, a4, a5, a6) VALUES ('" . $_POST['a1']. "','" . $_POST['a2']. "','" . $_POST['a3']. "','" . $_POST['a4']. "', '" . $_POST['a5']. "', '" . $_POST['a6']. "')") or exit( mysql_error() );

	header ("Location: addpoll.php?note=1");
die();
}

?>
<?
// Error messages

if ($_GET['error'] == '1') {
	$note = "<br><center>
			 <table border='1' cellpadding='0' cellspacing='0' style='border-collapse: collapse' width='75%' id='AutoNumber1' bordercolor='red' bgcolor='#000000'>
				<tr>
				  <td width='100%' align='center'><font color='red' size='2'><b>You have to enter a Subject!</b></font></td>
				</tr>
			 </table>
			 </center><br>";
	}

if ($_GET['error'] == '2') {
	$note = "<br><center>
			 <table border='1' cellpadding='0' cellspacing='0' style='border-collapse: collapse' width='75%' id='AutoNumber1' bordercolor='red' bgcolor='#000000'>
				<tr>
				  <td width='100%' align='center'><font color='red' size='2'><b>You have to enter a Message!</b></font></td>
				</tr>
			 </table>
			 </center><br>";
	}

// Note messages

if ($_GET['note'] == '1') {
	$note = "<br><center>
			 <table border='1' cellpadding='0' cellspacing='0' style='border-collapse: collapse' width='75%' id='AutoNumber1' bordercolor='red' bgcolor='#000000'>
				<tr>
				  <td width='100%' align='center'><font color='red' size='2'><b>Your news has been posted successfully!</b></font></td>
				</tr>
			 </table>
			 </center><br>";
	}
?>
<div align="center">
  <center>
<table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="75%" id="AutoNumber2" bgcolor="#ffffff">
<form action="addpoll.php?action=post" method="post">
  <tr>
    <td width="100%" bgcolor="#ffffff" align="center"><font size="2"><b>Post News On Homepage</b></font></td>
  </tr>
  <tr>
    <td width="100%" align="center"> </td>
  </tr>
  <tr>
  <td width="100%" align="center"><input type="hidden" name="userid" value="<?=$userid;?>"></td>
  </tr>
  <tr>
    <td width="100%" align="center"><b>Your Question:</b></td>
  </tr>
  <tr>
    <td width="100%" align="center"><input type="text" name="question" maxlength="255" size="30"></td>
  </tr>
  <tr>
    <td width="100%" align="center"> </td>
  </tr>
  <tr>
    <td width="100%" align="center"><b>Answers:</b></td>
  </tr>
  <tr>
    <td width="100%" align="center">1. <input type="text" name="a1" maxlength="50" size="32"></td>
  </tr>
  <tr>
    <td width="100%" align="center"> </td>
  </tr>
  <tr>
    <td width="100%" align="center">2. <input type="text" name="a2" maxlength="50" size="32"></td>
  </tr>
  <tr>
    <td width="100%" align="center"> </td>
  </tr>
  <tr>
    <td width="100%" align="center"><input type="submit" value="Post News" name="B1"></td>
  </tr>
</div>
</body>
</html>
</form>
</table>
  </center>
</div>

 

Thanks

Rich

Link to comment
Share on other sites

well im using php for the code.

 

I realize that. But php is ONLY done on your server. if you want something to change without reloading the page(like your case), you HAVE to use javascript. There's no other way around it. And doing this by reloading the page a bunch is gonna get REALLY confusing, more so than just handling it with javascript.

 

it would be something like this

<select id="select_id" onChange="show();">
<option value="13452346345766354">Won't do it</option>
<option value="1234">Will do it</option>
</select>

<div id="1234" style="display:none">content to show!</div>

<script type="text/javascript">
function show(){
var what = document.getElementById('select_name').value;

if(what == "1234"){
document.getElementById('1234').style.display= " ";
}


}
</script>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.