Hi!
I am trying to create a simple online survey (using PHP and MySQL) which includes radio buttons, checkboxes and textareas.
Before posting this question, I spent quite a while reading the previously posted questions and responses about topics similar to mine. But for some reason, I could not figure out. I am a real novice in PHP and MySQL.
I will truly appreciate if you experts may kindly help me out.
Thanks a lot!
duta
Tuesday (May 23, 2006) at 11:13 a.m.
__________ form.php __________________________
__________
__________
<html>
<head><title>PHP Survey-</title></head>
<body>
<form action="process.php" method="POST">
<ul>
<b>Please fill the form accurately.</b></FONT></ul
>
<ul><ul>
<P><li><strong>Gender:</st
rong><br>
<INPUT TYPE="RADIO" NAME="gender" value="male" size="35"> Male<br>
<INPUT TYPE="RADIO" NAME="gender" value="female" size="35"> Female<br>
<INPUT TYPE="RADIO" NAME="gender" value="neutral" size="35"> Neutral<br>
</li>
<P><li><strong>Favorite Fruits:</strong><br>
<INPUT TYPE="checkbox" NAME="fruit" value="Apple" size="35"> Apple<br>
<INPUT TYPE="checkbox" NAME="fruit" value="Orange" size="35"> Orange<br>
<INPUT TYPE="checkbox" NAME="fruit" value="Banana" size="35">Banana<br>
</li>
<p><li><strong>What is your evaluation of this movie?</strong><p>
<select name="movie">
<option> Awesome!
<option> Good
<option> Poor
</select>
</li>
</ul></ul>
<ul><ul>
<p><li><strong>Write about Your Work Attitude: </strong><br>
<textarea NAME="block" cols="80" rows="10"><?php echo $_POST['block'] ?></textarea>
<br><br>
<INPUT TYPE="SUBMIT" NAME="SUBMIT" VALUE="SUBMIT" >
<INPUT TYPE="RESET" NAME="RESET" VALUE="RESET">
</li>
</ul></ul>
</FORM>
<hr>
</body>
</html>
______________ process.php __________________________
__________
_________
<html>
<head>
<title>PHP Survey</title>
</head>
<body>
<?php
$gender = $_POST['gender'];
$fruit=$_POST['fruit'];
$movie = stripslashes($_POST['movie
']);
$attitude =$_POST['block'];
if (!isset($gender))
echo("You didn't enter your gender<br>");
if (!isset($fruit))
echo("You didn't enter your race.<br>");
if (!isset($movie))
echo("You didn't enter your evaluation<br>");
if ( !isset($gender) || !isset($fruit) || !isset($movie) || !isset($attitude))
{
echo("<h3>" .$fname.",You responded the questions accurately; Thanks!</h3>");
echo "<h4> Here are your records </h4>";
echo ("<p>Gender: " . $gender);
echo ("<p>Fruits: " . $fruit);
echo ("<p>Movie: " . $movie);
echo ("<p>Attitude: " . $_POST['block']);
}
else
{
echo("<h2>Please, answer all questions</h2>");
}
$to = 'duta@hotmail.com'';
// subject
$subject = 'Testing survey4 ';
// message
$message1 = "
<html>
<head>
<title>Your Response </title>
</head>
<body>
<p>Here are Your Response</p>
<table width='76%' border='1' cellspacing='1' cellpadding='1'>
<tr>
<th> Gender </th><th>Fruits</th><th>Mo
vie</th><t
h></th><th
>Attitude<
/th></tr>
<tr>
<td align='center'>$gender</td
><td align='center'>$fruits</td
><td align='center'>$movie</td>
<td align='center'>$attitude</
td></tr>
</table>
</body>
</html>
";
// $headers="<h2>Online Survey</h2>";
mail($to, $subject, $message1, $headers);
$conn = mysql_connect("localhost",
"my_user_n
ame", "my_password");
if (!$conn)
{ die ('Could not connect:' . mysql_error());}
else
{echo "You are connected!<br>";}
$sql="Create database my_db";
mysql_query ($sql, $conn);
mysql_select_db ("my_db", $conn);
// Create table
$sql="create table my_table (gender enum('female', 'male', 'neutral'),fruit enum('apple' 'orange', 'banana'), movie enum('awesome', 'good', 'poor'), attitude text)";
mysql_query($sql, $conn);
// Insert date into MySql table
mysql_query ( "INSERT INTO my_table(gender,fruit,movi
e,attitude
)
VALUES ('$gender', '$fruit','$movie','$attitu
de') " );
echo "<br> Data inserted!";
// Output client's input
echo "<table width='76%' border='1' cellspacing='1' cellpadding='1'><tr><th>
Gender</th><th>Fruit</th><
th>Email</
th><th>Mov
ie</th><th
>Attitude<
/th>";
$result =mysql_query("SELECT * FROM my_table");
while ($row=mysql_fetch_array($r
esult))
{
echo '<tr><td>';
echo $row['gender'];
echo '</td>';
echo '<td>';
echo $row['fruit'];
echo '</td>';
echo '<td>';
echo $row['movie'];
echo '</td>';
echo '<td>';
echo $row['attitude'];
echo '</td>';
echo "</tr><br>";
}
echo "</table>";
?>
</body>
</html>
__________________________
__________
__________
__________
__________
__________
_________