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"> </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>