validation problemo

Thread Solved

Join Date: Feb 2008
Posts: 22
Reputation: jinchiruki is an unknown quantity at this point 
Solved Threads: 0
jinchiruki jinchiruki is offline Offline
Newbie Poster

validation problemo

 
0
  #1
Feb 12th, 2008
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['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)
{
// Process form
}
else
{
echo $errors[0];
}
?>


(added.php)
<?php


include("connect.php");
if (
$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();
?>



(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>
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 570
Reputation: ryan_vietnow is an unknown quantity at this point 
Solved Threads: 71
ryan_vietnow's Avatar
ryan_vietnow ryan_vietnow is offline Offline
Posting Pro

Re: validation problemo

 
0
  #2
Feb 12th, 2008
what is exactly the problem?
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 22
Reputation: jinchiruki is an unknown quantity at this point 
Solved Threads: 0
jinchiruki jinchiruki is offline Offline
Newbie Poster

Re: validation problemo

 
0
  #3
Feb 12th, 2008
validation doesnt workout.
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 570
Reputation: ryan_vietnow is an unknown quantity at this point 
Solved Threads: 71
ryan_vietnow's Avatar
ryan_vietnow ryan_vietnow is offline Offline
Posting Pro

Re: validation problemo

 
0
  #4
Feb 12th, 2008
put your validation inside your added.php.If there are errors found then die the statement.

example:
(added.php)
  1. //this is your validation in the form,put it here....
  2.  
  3. if (empty($_POST['name']))
  4. {
  5. $errors[] = 'Please enter a name';
  6. }
  7.  
  8.  
  9.  
  10. if (empty($_POST['email']))
  11. {
  12. $errors[] = 'Please enter an e-mail';
  13. }
  14. else if (!eregi("^[_a-z0-9-]+(.[_a-z0-9-]+)*@[a-z0-9-]+(.[a-z0-9-]+)*(.[a-z]{2,3})$", $_POST['email']))
  15. {
  16. $errors[] = 'Please enter a valid e-mail address';
  17. }
  18.  
  19.  
  20. if (empty($_POST['contact']))
  21. {
  22. $errors[] = 'Please enter a contact';
  23. }
  24. else if (!is_numeric($_POST['contact']))
  25. {
  26. $errors[] = 'Please enter a valid contact with a numeric value';
  27. }
  28.  
  29.  
  30. if (empty($_POST['person_attend']))
  31. {
  32. $errors[] = 'Please enter some word';
  33. }
  34. else if (strlen ($_POST['comments']) > 255)
  35. {
  36. $errors[] = 'Your comment is too long, please do not submit more then 255 characters';
  37.  
  38.  
  39.  
  40.  
  41. if (empty($_POST['comment']))
  42. {
  43. $errors[] = 'Please enter some comment';
  44. }
  45. else if (strlen ($_POST['comment']) > 255)
  46. {
  47. $errors[] = 'Your comment is too long, please do not submit more then 255 characters';
  48.  
  49.  
  50. if (count($errors) > 0)
  51. {
  52. die(echo $errors[0];);
  53.  
  54. }
  55. else
  56. {
  57. //process form
  58.  
  59.  
  60. //this is your add query....
  61. $name = $_POST['name'];
  62. $email = $_POST['email'];
  63. $contact = $_POST['contact'];
  64. $person_attend = $_POST['person_attend'];
  65. $comment = $_POST['comment'];
  66.  
  67.  
  68. $query = "INSERT INTO rsvp (id, name, email, contact, person_attend, comment)
  69. VALUES ('', '$name', '$email', '$contact', '$person_attend', '$comment')";
  70.  
  71. $results = mysql_query($query) or die
  72. ("Could not execute query : $query." . mysql_error());
  73.  
  74.  
  75. {
  76. echo "thanks you ";
  77. }
  78. mysql_close();
  79. }
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 22
Reputation: jinchiruki is an unknown quantity at this point 
Solved Threads: 0
jinchiruki jinchiruki is offline Offline
Newbie Poster

Re: validation problemo

 
0
  #5
Feb 12th, 2008
thanxs for ur help pal..
but still..had problemo...


parse error
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 3,761
Reputation: nav33n is a jewel in the rough nav33n is a jewel in the rough nav33n is a jewel in the rough 
Solved Threads: 332
Moderator
Featured Poster
nav33n's Avatar
nav33n nav33n is offline Offline
Senior Poster

Re: validation problemo

 
0
  #6
Feb 12th, 2008
which line ?
Ignorance is definitely not bliss!

*PM asking for help will be ignored*
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 22
Reputation: jinchiruki is an unknown quantity at this point 
Solved Threads: 0
jinchiruki jinchiruki is offline Offline
Newbie Poster

Re: validation problemo

 
0
  #7
Feb 13th, 2008
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>
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 3,761
Reputation: nav33n is a jewel in the rough nav33n is a jewel in the rough nav33n is a jewel in the rough 
Solved Threads: 332
Moderator
Featured Poster
nav33n's Avatar
nav33n nav33n is offline Offline
Senior Poster

Re: validation problemo

 
0
  #8
Feb 13th, 2008
  1. else if (strlen ($_POST['person_attend']) > 255)
  2.  
  3. {
  4.  
  5. $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.
Last edited by nav33n; Feb 13th, 2008 at 3:14 am.
Ignorance is definitely not bliss!

*PM asking for help will be ignored*
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 22
Reputation: jinchiruki is an unknown quantity at this point 
Solved Threads: 0
jinchiruki jinchiruki is offline Offline
Newbie Poster

Re: validation problemo

 
0
  #9
Feb 19th, 2008
suggest me good editor pls..still cant fix myproblem..learnin.
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 3,761
Reputation: nav33n is a jewel in the rough nav33n is a jewel in the rough nav33n is a jewel in the rough 
Solved Threads: 332
Moderator
Featured Poster
nav33n's Avatar
nav33n nav33n is offline Offline
Senior Poster

Re: validation problemo

 
0
  #10
Feb 19th, 2008
You can try Notepad++ or devphp. There are many more free ide's available.
Ignorance is definitely not bliss!

*PM asking for help will be ignored*
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the PHP Forum


Views: 1019 | Replies: 13
Thread Tools Search this Thread



Tag cloud for PHP
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC