Jump to content

first attempt


juniorek9

Recommended Posts

Hi all.

I`m starting with the php programming and i try to create a simple questionnaire

i want to ask few questions with few possible answers

could anyone give me any sample how the code should look like, i`ve created few quetsions but they are all seperate code, how can i put them together into one code?

any suggestions?

Thanks

 

[attachment deleted by admin]

Link to comment
Share on other sites

it isn't your first attempt, as that you posted earlier in this forum...

 

you should mess around with echo post data from forms.

 

<form method="post" action="">

<input type="text" name="var" />

</form>

 

<?php

$array[]='string1';

$array[]='string2';

$array[]='string3';

foreach($array AS $string){

  if(!empty($_POST['var'])){

    if($_POST['var']==$string){

      echo $_POST['var'].' is the same as '.$string;

    }

  }

}

?>

Link to comment
Share on other sites

Did you try searching

 

"php questionnaire tutorial"

 

In google?

 

http://www.google.co.uk/search?q=php+questionnaire+tutorial&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:en-GB:official&client=firefox-a

 

There's tons of tutorials on this kind of stuff. Also, you might want to try search for "php survey tutorial" too.

 

Hope that helps.

Link to comment
Share on other sites

<?php
if(isset($_POST['submit'])) {
foreach($_POST as $k => $v) {
	echo $k . ' = ' . $v;

	if($_POST[$v] == 'the right answer') {
		echo 'well done you got ' . $_POST[$k] . ' right';
	} else {
		echo 'you have failed';
	}
}
}

$transport = array('r' => 'Cruise the street in your hot ride',
                 'a' => 'Join the army',
                 'p' => 'go to a science convention',
			 'h' => 'stay home and work on the computer');
foreach ($transport as $key => $transport) {
   $return .= '<input type="radio" name="transport" value="' . $key . '"/> ' . $transport . '<br/>';
}

echo '<form action="" method="">' . $return . '<input type="submit" name="submit"></form>';

 

James.

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.