here is the full code.....
What i am trying to do is
to check the form details have been filled in if it has then process as normal, if the fields are empty then display error and do not process...... and the final check is to make sure that at least a minimum amout of chars have been entered into the fields......
all these conditions should be checked when the sumbit = isset ......
any help as per usual will be much appreicated......
<?php
//Application: Survey
//Purpose: This is the main page of the survey application. It prints
//out the survey form (which posts to thanks.php), as well as a link
//to the main results page (results.php).
//It is accessed directly by the user.
include "header.php";
include "start_page.php";
include "functions.php";
include "config1.php";
?>
<CENTER>
<IMG SRC="world.jpg" ALT=""></img>
<p>
Thanks for filling out the survey. Be sure to fill out all the questions,
and become eligible for our weekly prize drawings!
Please, only one entry per person.
</p>
<p>
</p>
<BR><BR><BR><BR>
</CENTER>
<?php
// begin the survey form.
print start_form("thanks.php");
// get the current survey questions from the database and display
// them to the user for voting.
print subtitle("Start the questions:");
$query = "select question_id, question from questions q order by question_id";
$result = safe_query($query);
// set the name of each question and each answer field
// in the "field[]" format. PHP will treat the values
// of these fields as arrays when the form is submitted.
// we start the field index at 1 to avoid any problems
// with the index seeming to be empty.
$i = 1;
while (list($question_id, $question) = mysql_fetch_row($result))
{
// use the db_radio_field() function (defined in
// /book/functions/forms.php) to construct a list
// of radio fields for each answer to the question.
print paragraph(
"<b>$question:</b><br>"
, hidden_field("question_id[$i]", $question_id)
, db_radio_field("answer_id[$i]"
, "answers", "answer_id", "answer", "answer_id"
, "" // no matching value
, "question_id = $question_id"
)
);
$i++;
}
print "<BR><BR>";
// print out fields for the user to fill in.
print subtitle("Please enter your personal details:");
?>
<html>
<head>
<!-- <title><?php print $title ?></title>-->
<form action="<?=$_SERVER["PHP_SELF"]?>" method="POST">
<table>
<tr><td>Name:</td><td><input type="text" name="name" value=""
<?php print isset($_POST["name"]) ? $_POST["name"] : "" ;?>"
maxlength="40"></td></tr>
<tr><td>Email</td><td><input type="text" name="email" value="" maxlength="40"></td></tr>
<tr><td>Confirm Email </td><td><input type="text" name="email2" value="" maxlength="40"></td></tr>
<tr><td>Age </td><td><input type="text" name="age" value="" maxlength="3"></td></tr>
</table>
<?php
$messages[]="Your passwords did not match";
if(isset($_POST["submit"]))
{
// Info has been submitted, check it:
if(!empty($messages))
{
displayErrors($messages);// Check login, password and password2 are not empty:
}
if(empty($messages))
{
// registration ok, get user id and update db with new info:
newUser($_POST["name"], $_POST["password"], $_POST["age"] );
}
if(strcmp($_POST["email"], $_POST["email2"]))
{
// The password and confirmation password didn't match,
// Add a message to be displayed to the user:
$messages[]="Your passwords did not match";
}
if( ($row=mysql_fetch_array($result)) )
{
$messages[]="Name \"".$_POST["name"]."\" already exists. Try another.";
}
#field_validator($field_descr, $field_data, $field_type, $min_length="", $max_length="", $field_required=1)
field_validator("name", $_POST["name"], "alphanumeric", 4, 30);
field_validator("email", $_POST["email"], "string", 4, 30);
field_validator("confirm email", $_POST["email2"], "string", 4, 30);
field_validator("age", $_POST["age"], "string", 1, 3);
$query="SELECT guestbook2k FROM users WHERE name='".$_POST["name"]."'";
$result=mysql_query($query, $link) or die("MySQL query $query failed. Error if any: ".mysql_error());
}
print paragraph(submit_field("submit","Submit Survey"), reset_field());
//end the survey form.
print end_form();
include "end_page.php";
?>
</form>
</body>
</html>