need some advise here...just create a simple form..but i had problem with validation.hope somebody can help me..

(register.html)


<form id="FormName" name="name"method="post" action="added.php" name="name">
<input id="name" name="name"type="text" name="name"><br>
<input id="email" name="email"tpe="text" name="email"><br>
<input id="contact" name="contact"type="int" name="contact"><br>
<textarea id="person_attend" name="person_attend" rows="4" cols="40"></textarea>
<textarea id="comment" name="comment" rows="4" cols="40"></textarea>

<input type="submit" name="submit">


</form>


<?


include("connect.php");


if (empty($_POST))
{
$errors[] = 'Please enter a name';
}

if (empty($_POST))
{
$errors[] = 'Please enter an e-mail';
}
else if (!eregi("^[_a-z0-9-]+(.[_a-z0-9-]+)*@[a-z0-9-]+(.[a-z0-9-]+)*(.[a-z]{2,3})$", $_POST))
{
$errors[] = 'Please enter a valid e-mail address';
}


if (empty($_POST))
{
$errors[] = 'Please enter a contact';
}
else if (!is_numeric($_POST))
{
$errors[] = 'Please enter a valid contact with a numeric value';
}


if (empty($_POST))
{
$errors[] = 'Please enter some word';
}
else if (strlen ($_POST) > 255)
{
$errors[] = 'Your comment is too long, please do not submit more then 255 characters';


if (empty($_POST))
{
$errors[] = 'Please enter some comment';
}
else if (strlen ($_POST) > 255)
{
$errors[] = 'Your comment is too long, please do not submit more then 255 characters';
if (count($errors) == 0)
{
// Process form
}
else
{
echo $errors[0];
}
?>


(added.php)
<?php


include("connect.php");
if (
$name = $_POST;
$email = $_POST;
$contact = $_POST;
$person_attend = $_POST;
$comment = $_POST;
)

$query = "INSERT INTO rsvp (id, name, email, contact, person_attend, comment)
VALUES ('', '$name', '$email', '$contact', '$person_attend', '$comment')";

$results = mysql_query($query) or die
("Could not execute query : $query." . mysql_error());


{
echo "thanks you ";
}
mysql_close();
?>

(connect.php)

<?php
define('DB_HOST' , 'localhost');
define('DB_NAME' , 'rsvp');
define('DB_USERNAME' , 'root');
define('DB_PASSWORD' , '');

$conn = mysql_connect(DB_HOST, DB_USERNAME )
or die(mysql_error());mysql_select_db(DB_NAME);
?>

(Index.php)


<table width="1000" height="95" border="1">
<tr>
<td bgcolor="#0000FF">&nbsp;</td>
</tr>
</table>
<p>


<center><a href="register.html">Click here for register</a><br>
<br>


<p>
<b> <html> Attend List; </html> </b><p>
<?php


include("connect.php");

$query="SELECT * FROM rsvp ";
$result=mysql_query($query);
$num = mysql_num_rows ($result);
mysql_close();

if ($num > 0 )

{
$i=0;
while ($i < $num)


{
$name = mysql_result($result,$i,"name");
$email = mysql_result($result,$i,"email");
$contact = mysql_result($result,$i,"contact");
$person_attend = mysql_result($result,$i,"person_attend");
$comment = mysql_result($result,$i,"comment");
$id = mysql_result($result,$i,"id");

echo "<b>Name:</b> $name<br>";
echo "<b>Email:</b> $email<br>";
echo "<b>Contact:</b> $contact<br>";
echo "<b>Person attend:</b> $person_attend<br>";
echo "<b>Comment:</b> $comment<br>";

echo "<br><br>";

++$i; }


} else { echo "No one yet register"; }
?>
</center>

put your validation inside your added.php.If there are errors found then die the statement.

example:
(added.php)

//this is your validation in the form,put it here....

if (empty($_POST['name']))
{
$errors[] = 'Please enter a name';
}



if (empty($_POST['email']))
{
$errors[] = 'Please enter an e-mail';
}
else if (!eregi("^[_a-z0-9-]+(.[_a-z0-9-]+)*@[a-z0-9-]+(.[a-z0-9-]+)*(.[a-z]{2,3})$", $_POST['email']))
{
$errors[] = 'Please enter a valid e-mail address';
}


if (empty($_POST['contact']))
{
$errors[] = 'Please enter a contact';
}
else if (!is_numeric($_POST['contact']))
{
$errors[] = 'Please enter a valid contact with a numeric value';
}


if (empty($_POST['person_attend']))
{
$errors[] = 'Please enter some word';
}
else if (strlen ($_POST['comments']) > 255)
{
$errors[] = 'Your comment is too long, please do not submit more then 255 characters';




if (empty($_POST['comment']))
{
$errors[] = 'Please enter some comment';
}
else if (strlen ($_POST['comment']) > 255)
{
$errors[] = 'Your comment is too long, please do not submit more then 255 characters';


if (count($errors) > 0)
{
die(echo $errors[0];);

}
else
{
//process form


//this is your add query....
$name = $_POST['name'];
$email = $_POST['email'];
$contact = $_POST['contact'];
$person_attend = $_POST['person_attend'];
$comment = $_POST['comment'];


$query = "INSERT INTO rsvp (id, name, email, contact, person_attend, comment)
VALUES ('', '$name', '$email', '$contact', '$person_attend', '$comment')";

$results = mysql_query($query) or die 
("Could not execute query : $query." . mysql_error());


 {
echo "thanks you ";
}
mysql_close();
}
Parse error: parse error in c:\program files\easyphp1-8\www\rsvp\added.php on line 111



<table width="1000" height="95" border="1">
  <tr>
    <td bgcolor="#0000FF">&nbsp;</td>
  </tr>
</table>



<?
   include("connect.php");

      //this is your validation in the form,put it here....



      if (empty($_POST['name']))

      {

      $errors[] = 'Please enter a name';

      }







      if (empty($_POST['email']))

      {

      $errors[] = 'Please enter an e-mail';

      }

      else if (!eregi("^[_a-z0-9-]+(.[_a-z0-9-]+)*@[a-z0-9-]+(.[a-z0-9-]+)*(.[a-z]{2,3})$", $_POST['email']))

      {

      $errors[] = 'Please enter a valid e-mail address';

      }





      if (empty($_POST['contact']))

      {

      $errors[] = 'Please enter a contact';

      }

      else if (!is_numeric($_POST['contact']))

      {

      $errors[] = 'Please enter a valid contact with a numeric value';

      }





      if (empty($_POST['person_attend']))

      {

      $errors[] = 'Please enter some word';

      }

      else if (strlen ($_POST['person_attend']) > 255)

      {

      $errors[] = '';









      if (empty($_POST['comment']))

      {

      $errors[] = 'Please enter some comment';

      }

      else if (strlen ($_POST['comment']) > 255)

      {

      $errors[] = ' ';

      if (count($errors) > 0)

      {

      die(echo $errors[0] );



      }

      else

      {

      //process form




      //this is your add query....

      $name = $_POST['name'];

      $email = $_POST['email'];

      $contact = $_POST['contact'];

      $person_attend = $_POST['person_attend'];

      $comment = $_POST['comment'];





      $query = "INSERT INTO rsvp (id, name, email, contact, person_attend, comment)

      VALUES ('', '$name', '$email', '$contact', '$person_attend', '$comment')";



      $results = mysql_query($query) or die

      ("Could not execute query : $query." . mysql_error());





      {

      echo "thanks you ";

      }

      mysql_close();

      }

?>

<br>
<a href="Index.php">View list attend</a>

Edited 3 Years Ago by mike_2000_17: Fixed formatting

else if (strlen ($_POST['person_attend']) > 255)

{

$errors[] = '';

Opened { and never closed. And next time, Please post your code within code tags.

Edit: Btw, I still think there are many unclosed braces. Get a good editor, match the braces and close it accordingly.

Edited 3 Years Ago by happygeek: fixed formatting

<table width="1000" height="95" border="1">
  <tr>
    <td bgcolor="#0000FF">&nbsp;</td>
  </tr>
</table>

<center>

<?
   include("connect.php"); 
      //this is your validation in the form,put it here....
    { if (empty($_POST['name']))
      { 
      $errors[] = 'Please enter a name';
      }
      if (empty($_POST['email']))
      {
      $errors[] = 'Please enter a valid e-mail address';
      }
      else if (!eregi("^[_a-z0-9-]+(.[_a-z0-9-]+)*@[a-z0-9-]+(.[a-z0-9-]+)*(.[a-z]{2,3})$", 
      $_POST['email']))
      {
      $errors[] = 'Please enter a valid e-mail address';
      }
      if (empty($_POST['contact']))
      {
      $errors[] = 'Please enter a valid contact with numeric value';
      }
      else if (!is_numeric($_POST['contact']))
      {
      $errors[] = 'Please enter a valid contact with a numeric value';
      }
      
      
      if (empty($_POST['person_attend']))
      {
      $errors[] = 'Please enter some word for person attend';
      }
      
      
      else if (strlen ($_POST['person_attend']) > 255)
      {
      $errors[] = 'person attend';
   }
   
   
   
      if (empty($_POST['comment']))
      {
      $errors[] = 'Please enter some comment';
      }
      else if (strlen ($_POST['comment']) > 255)
      {
      $errors[] = 'comment ';
  
 }
 
      if(isset($errors))
{

	foreach($errors as $val)
	{
	
		echo "Error: $val <br/>"; 
	}
}
 
 
      if($name="" && $email="" && $contact="" && $person_attend="" && $comment="" )
      
      {
 
      //insert statements
 
      } else {
 
      //error message
 
      }
 
      //process form
 
      //this is your add query....
  
      $name = $_POST['name'];
 
      $email = $_POST['email'];
 
      $contact = $_POST['contact'];
 
      $person_attend = $_POST['person_attend'];
  
      $comment = $_POST['comment'];
 
      $query = "INSERT INTO rsvp (id, name, email, contact, person_attend, comment)
   
      VALUES ('', '$name', '$email', '$contact', '$person_attend', '$comment')";
      
      $results = mysql_query($query) or die
  
      ("Could not execute query : $query." . mysql_error());
    
      {
 
      echo "thanks you ";
 
      }
   
      mysql_close();
 }
      

?>
</center>
<center> 
<br>
<a href="Index.php">View list attend</a><br>
<a href="register.html">Clik here to register</a>
</center>

what u guys think bout mycode??retarded??hehhe..

i want to set if i didnt fill the form,then click sumbit,it didnt query to database and show in list.

<table width="1000" height="95" border="1">
  <tr>
    <td bgcolor="#0000FF">&nbsp;</td>
  </tr>
</table>

<center>

<?
   include("connect.php"); 
      //this is your validation in the form,put it here....
       if (empty($_POST['name']))
      { 
      $errors[] = 'Please enter a name';
      }
      if (empty($_POST['email']))
      {
      $errors[] = 'Please enter a valid e-mail address';
      }
      else if (!eregi("^[_a-z0-9-]+(.[_a-z0-9-]+)*@[a-z0-9-]+(.[a-z0-9-]+)*(.[a-z]{2,3})$", 
      $_POST['email']))
      {
      $errors[] = 'Please enter a valid e-mail address';
      }
      if (empty($_POST['contact']))
      {
      $errors[] = 'Please enter a valid contact with numeric value';
      }
      else if (!is_numeric($_POST['contact']))
      {
      $errors[] = 'Please enter a valid contact with a numeric value';
      }
      
      
      if (empty($_POST['person_attend']))
      {
      $errors[] = 'Please enter some word for person attend';
      }
      
      
      else if (strlen ($_POST['person_attend']) > 255)
      {
      $errors[] = 'person attend';
   }
   
   
   
      if (empty($_POST['comment']))
      {
      $errors[] = 'Please enter some comment';
      }
      else if (strlen ($_POST['comment']) > 255)
      {
      $errors[] = 'comment ';
  
 }
 
      
 
 
      if($name="" && $email="" && $contact="" && $person_attend="" && $comment="" )
      
      {
 //process form
 
      //this is your add query....
  
      $name = $_POST['name'];
 
      $email = $_POST['email'];
 
      $contact = $_POST['contact'];
 
      $person_attend = $_POST['person_attend'];
  
      $comment = $_POST['comment'];
 
      $query = "INSERT INTO rsvp (id, name, email, contact, person_attend, comment)
   
      VALUES ('', '$name', '$email', '$contact', '$person_attend', '$comment')";
      
      $results = mysql_query($query) or die ("Could not execute query : $query." . mysql_error());
		if($result){
      echo "thanks you ";
		}
       mysql_close();
     
 
      } else {
 if(isset($errors))
{

	foreach($errors as $val)
	{
	
		echo "Error: $val <br/>"; 
	}
}
      	
      }
 
      
      

?>
</center>
<center> 
<br>
<a href="Index.php">View list attend</a><br>
<a href="register.html">Clik here to register</a>
</center>

Try this.

small mistake. Try this.

<table width="1000" height="95" border="1">
  <tr>
    <td bgcolor="#0000FF">&nbsp;</td>
  </tr>
</table>

<center>

<?
   include("connect.php"); 
      //this is your validation in the form,put it here....
       if (empty($_POST['name']))
      { 
      $errors[] = 'Please enter a name';
      }
      if (empty($_POST['email']))
      {
      $errors[] = 'Please enter a valid e-mail address';
      }
      else if (!eregi("^[_a-z0-9-]+(.[_a-z0-9-]+)*@[a-z0-9-]+(.[a-z0-9-]+)*(.[a-z]{2,3})$", 
      $_POST['email']))
      {
      $errors[] = 'Please enter a valid e-mail address';
      }
      if (empty($_POST['contact']))
      {
      $errors[] = 'Please enter a valid contact with numeric value';
      }
      else if (!is_numeric($_POST['contact']))
      {
      $errors[] = 'Please enter a valid contact with a numeric value';
      }
      
      
      if (empty($_POST['person_attend']))
      {
      $errors[] = 'Please enter some word for person attend';
      }
      
      
      else if (strlen ($_POST['person_attend']) > 255)
      {
      $errors[] = 'person attend';
   }
   
   
   
      if (empty($_POST['comment']))
      {
      $errors[] = 'Please enter some comment';
      }
      else if (strlen ($_POST['comment']) > 255)
      {
      $errors[] = 'comment ';
  
 }
 
      $name = $_POST['name'];
 
      $email = $_POST['email'];
 
      $contact = $_POST['contact'];
 
      $person_attend = $_POST['person_attend'];
  
      $comment = $_POST['comment'];
 
      
 
 
      if($name="" && $email="" && $contact="" && $person_attend="" && $comment="" )
      
      {
 //process form
 
      //this is your add query....
  
      $query = "INSERT INTO rsvp (id, name, email, contact, person_attend, comment)
   
      VALUES ('', '$name', '$email', '$contact', '$person_attend', '$comment')";
      
      $results = mysql_query($query) or die ("Could not execute query : $query." . mysql_error());
		if($result){
      echo "thanks you ";
		}
       mysql_close();
     
 
      } else {
 if(isset($errors))
{

	foreach($errors as $val)
	{
	
		echo "Error: $val <br/>"; 
	}
}
      	
      }
 
      
      

?>
</center>
<center> 
<br>
<a href="Index.php">View list attend</a><br>
<a href="register.html">Clik here to register</a>
</center>

If that doesn't work, then you have to check the flow by putting your own message in appropriate places(eg, loops and conditions).

This question has already been answered. Start a new discussion instead.