Poll with comment field

Heya,

I’m trying to find a really basic script which we’re going to use at work.
Downloaded a couple scripts but they seem really advanced and I havent been able to add a comment field on them. (too newb). Anyone who can help me?

The question and the options will always be the same, and we reset it each week.
We also want the employees to send a comment to the option they chose.

Should look something like:

QUESTION - BLABLABLA?

  • Option 1 radiobutton

  • Option 2 radiobutton

  • Option 3 radiobutton

  • Option 4 radiobutton

  • Option 5 radiobutton

  • COMMENT textarea

Best would be if it’s stored in a database. And that it’s cookie based so they can’t spam vote.

Anyone who can help me?

Thanks alot in advance!

Although I’m not an expert in the field but I’ve managed to write a script for you that will do the work, Hope you will find it useful.

<!DOCTYPE html>
<html>
	<head>
		<title>Poll with Comment</title>
	</head>

	<body>

		<h2> Basic Form </h2>
				
<?php
			
		if ($_SERVER['REQUEST_METHOD'] == 'POST' &&
		isset($_POST['SbtQues']) &&	!empty($_POST['Question'])

		// Remove the '//' from the line below to make Comments Compulsory.
		// && !empty($_POST['comments'])
		){

			
			$host = 'localhost'; // Change localhost according to your needs.
			$user = 'abc'; // Change abc to your Database username.
			$pass = 'xyz'; // Change xyz to your Database username name's passowrd.
			$db = 'database'; // Change database to a database you want to store information.

			$conn = @mysqli_connect($host, $user, $pass, $db);

			if(!$conn) { die("Connection Failed");	}

				$question = $_POST['Question'];
				$comments = $_POST['comments'];
				$table = 'question'; // Change the word question to a table in which you want to save the information.

			$query = "INSERT INTO 
						{$table}  
					VALUES(
							'{$question}',
							'{$comments}'
							)";
			
			$results = mysqli_query($conn, $query);

			if (!$results){ die("Cant Insert the Record");	}
			else { echo "Thank You! Your Answer is Submitted."; }

		} 
		else 
		{ 
?>	
		<p> Your Question Here </p>
		<form method="post" action="">

			<p>
				<input type="radio" name="Question" value="Value1">Value1
			</p>
			
			<p>
				<input type="radio" name="Question" value="Value2">Value2
			</p>
			
			<p>
				<input type="radio" name="Question" value="Value3">Value3
			</p>
			
			<p>
				<input type="radio" name="Question" value="Value4">Value4
			</p>

			<p>
				<input type="radio" name="Question" value="Value5">Value5
			</p>

			<p>	
				<label for="comments">Insert Your Comments Here (Optional)</label> <br />
				<textarea name="comments" id="comments"	rows="4" cols="50"></textarea>

			</p>

			<p><input type="submit" name="SbtQues" value="Submit Your Answer"></p>

		</form>

<?php
		}
?>

	</body>

</html> 
Sponsor our Newsletter | Privacy Policy | Terms of Service