| | |
validation problemo
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved |
•
•
Join Date: Feb 2008
Posts: 22
Reputation:
Solved Threads: 0
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"> </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>
(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"> </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)
example:
(added.php)
php Syntax (Toggle Plain Text)
//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(); }
•
•
Join Date: Feb 2008
Posts: 22
Reputation:
Solved Threads: 0
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"> </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>
<table width="1000" height="95" border="1">
<tr>
<td bgcolor="#0000FF"> </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>
php Syntax (Toggle Plain Text)
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.
Last edited by nav33n; Feb 13th, 2008 at 3:14 am.
Ignorance is definitely not bliss!
*PM asking for help will be ignored*
*PM asking for help will be ignored*
![]() |
Similar Threads
- Help with Infostealer and Trojan.Metajuan (Viruses, Spyware and other Nasties)
Other Threads in the PHP Forum
- Previous Thread: Php random Slide showw
- Next Thread: Lost password reset / redirect user
Views: 1019 | Replies: 13
| Thread Tools | Search this Thread |
Tag cloud for PHP
.htaccess access ajax apache api array beginner binary broken cakephp checkbox class cms code cookies cron curl database date directory display download dynamic ebooks echo email error file files folder form forms function functions google href htaccess html image include insert integration ip java javascript joomla jquery limit link login loop mail mediawiki menu methods mlm mod_rewrite multiple mysql oop parse paypal pdf php problem query radio random recursion regex remote script search select server sessions sms soap source space speed sql stored structure subdomain syntax system table tutorial update updates upload url validation validator variable video web xml youtube






