Hi All,

Hi i am a newbie in PHP environment.

First of all my sincere regards to all behind developing this fabulous
language & of-course to every one who are sharing their knowledge & views
making others comfortable with the same.
Coming to the point i am trying to create a contact form applying server
side validation for my site using PHP. Here the problem had arises.
I have designed a from & applied validation referring the tutorials
available on web but unfortunately it is not working.
I am applying the validation & trying to show the error in the same field if
Here i am sending you the code snippet what i am trying to do. Your help is
highly appreciable. kindly help me out.

        $required =
        foreach($required as $field => $label){
                $warnings[$field] = "Required";
            if($_POST["email"] && !eregi
            $warnings["email"] = "Invalid Email Format";

            if($_POST["number"] && !eregi ("^[0-9]{10}$",$_POST["number"]))
            $warnings["number"] = "Invalid number Format";

    <!-- start form-->
<div class="post">
                <h2 class="title-credit">Contact Form:-</h2>
                <div class="entry" style="padding-left:30px;">
                    <form name="feedback" method="post" action="submit.php">
                        <p><div style="padding:3px;">Name <span
style="margin-left:20px"><input name="name" type="text" id="name" size="40"
<?php if($$warnings["name"]) echo 'style=\"shaded\"';?> value="<?php echo
$_POST["name"];?>"><?php echo $warnings["name"];?>></span></div>
                        <div style="padding:3px;">Number <span
style="margin-left:10px"><input name="number" type="text" id="number"
size="40" <?php if($$warnings["number"]) echo 'style=\"shaded\"';?>
value="<?php echo $_POST["number"];?>"><?php echo
                        <div style="padding:3px;">Email <span
style="margin-left:22px"><input name="email" type="text" id="email"
size="40" <?php if($$warnings["email"]) echo 'style=\"shaded\"';?>
value="<?php echo $_POST["email"];?>"><?php echo
                        <div style="padding:3px;">Comment <span
style="margin-left:0px"><textarea name="detail" cols="50" rows="4"
id="detail" <?php if($$warnings["detail"]) echo 'style=\"shaded\"';?>
value="<?php echo $_POST["detail"];?>"></textarea><?php echo
                        <div style="padding:3px; padding-left:150px;"><input
type="submit" name="Submit" value="Submit">
                        <input type="reset" name="Reset"
                        echo "Thanks for valuable comments";

$con=mysql_connect("localhost","test","test1234") or die
(mysql_errno().":<b> ".mysql_error()."</b>");
mysql_select_db("dbname",$con) or die (mysql_errno().":<b>

$insert_query = 'insert into GUESTBOOK (NAME,NUMBER,EMAIL,DETAIL) values(
                    "' . $_POST['name'] . '",
                    "' . $_POST['number'] . '",
                    "' . $_POST['email'] . '",
                    "' . $_POST['detail'] . '"
mysql_query($insert_query) or die ('Error updating database');
header('Location: http://www.sweetsamaira.com/guest.php');

Kindly help me out. Thanks in advance.

Kind Regards,
Vivek Jadiya

Reply via email to