can sumebody tell me whats wrong whis this code??
tried many times but still parse error..on line 53

and if i put validation on php,do i need to put the command at server side???
tq

<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[] = 'gogogogo';
   }
      if (empty($_POST['comment']))
      {
      $errors[] = 'Please enter some comment';
      }
      else if (strlen ($_POST['comment']) > 255)
      {
      $errors[] = 'comment ';
 }
      if (count($errors) > 0)
 
      {
      die(echo($errors)[0] );
      }
   
      else
 { echo "huhuhuhuh"; }
 
      //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>

on line 53 you say:

die(echo($errors)[0] );

to take care of the parse error you can change this to :

die($errors[0]);

however, that will only print the first error. If you want to print all of the errors, try changing this:

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

to this:

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

the validation settled..but new error comeout...

Notice: Undefined variable: errors in c:\program files\easyphp1-8\www\rsvp\added.php on line 51

There is nothing on line 51. Can you post your latest code (with CODE tags) ?

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($errors)
{
	foreach($errors as $val)
	{
		echo "ERROR: $val <br/>"; 
	}
}
 
      //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>
<br>
<a href="Index.php">View list attend</a>

Okay! notice is not an error. You can disable the notice by changing few lines in your php.ini file. Search for error_reporting and replace it with this. error_reporting = E_ALL & ~E_NOTICE & ~E_STRICT line from your php.ini file to disable notices. Anyway, try using if(isset($errors)){ instead of if($errors){ .

i think it solve already..shold i mark as solve cos i not sure yet..but its working..the validation,the input data query to database...and its come out like what i key in

hehehe..i think i faced 1 more problem...the form,if i didnt fill it up then click submit,its prompt to key in data to form and it query to database too.how to solve??

Check whether errors[0] is not equal to null or empty. If its null or empty, then query the database. If its not null, then there is some error !

how??? this is mycode.

//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();
 }
if($name !="" && $email!="" && $contact!="" && other variables not equal to null ){
//insert statements
} else {
//error message
}
<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>

flash it already,but then,still same..query tu db even no data was keyed a the form submit.how to tod?o
?

:) you have the insert statements outside the loop.
Put

//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();
 }

in place of //insert statements

This article has been dead for over six months. Start a new discussion instead.