Creating a questionnaire

I’m creating a questionnaire and I’m trying to do a couple of things.
I have 4 answers to each question a, b, c, d and 4 images, one representing each answer.
My first question is how do I set each of the images as a button for the answer?
My next question is how do I get the button to submit the answer to my database?

Thanks.

Well this is how I would tackle it:
[php]

What is the name of the stadium the Detroit Tigers play in?

  • answer1
  • answer2
  • answer3
  • answer4
[/php]

I would use unordered lists, anchor, and image tags but that isn’t the only way to do it for there are other HTML tag(s) you could use. I have also done it using form tags as well in the past, for that way you can use $_POST instead of $_GET. I use unordered lists, anchor and image tags for I find it the easiest to style in CSS. I usually design it first in HTML/CSS and then add the PHP components to the HTML after I get it designed. Again I find that easier. HTH John

Ok, ill try that.
Thanks alot :).

That worked, but I’ve now got another question lol.
The answers to the question are updating to my database fine, now before the redirect to the next question I’d like to display a message that says “you got it right/wrong” depending on there answer.
I assume this is some sort of an if statement but i cant quite figure it out.
Below is my insert code at the moment, im assuming this is where the if statement goes.

if ($ch) { // The value I’m passing to the database

// Add product data to the database:
$q = “INSERT INTO questionnaire (indice, q2, time_now)
VALUES (’$ind’, ‘$ch’, now())”;
$r = mysqli_query ($dbc, $q) or trigger_error("Query: $q\n
MySQL Error: " . mysqli_error($dbc));
if (mysqli_affected_rows($dbc) == 1) { // If it ran OK.

			echo '<center style="margin-left: 20px; margin-right: 20px"><h2>Thank you! Question 1 completed.</h2></center>';
			$_SESSION['page']='';
			header('Refresh: 3; URL=nextpage.php);



			exit(); // Stop the page.
			
		} else { // If it did not run OK.
			echo '<center><p class="error">Attempted duplicate entry. Please Wait!</p></center>';
			$_SESSION['page']='';
			header('Refresh: 3; URL=nextpage.php);

		}
			
} 

mysqli_close($dbc);
Sponsor our Newsletter | Privacy Policy | Terms of Service