Forum : form validation
Brief description  about Online courses   join in Online courses
View Noor  Mohammed 's Profile

form validation

Hellp sir,

Could you please let me know whats wrong with this code.

<?php

if ($_POST['submit'])

{

$name = $_POST['name'];
$age = $_POST['age'];
$occupation = $_POST['occupation'];

$errorstring = "";

if (!$name)
$errorstring = $errorstring."Name<br>";

if (!$age)
$errorstring = $errorstring."Age<br>";

if (!$occupation)
$errorstring = $errorstring."Occupation<br>";

if ($errorstring = "")

echo "Please fill out the following fields:<br>". $errorstring;

else
{
die ("success!");
}

}

?>
Asked by Noor Mohammed | Jan 20, 2011 |  Reply now
Replies (3)
View noor mohammed 's Profile
many thanks to you brother, but am still not getting it.
Jan 20, 2011
View mansoor ali 's Profile
In the submit button code of HTML,

Use type="submit" instead of using type="button".

Here is the complete correct code of your HTML page:


<html>
<body>
<form name="" action="formvalidation.php" method="post">

<table border="0" align="center" cellpadding="2" cellspacing="5"><tr><td>

Name: </td><td> <input type="text" name="name" /> </td></tr><tr><td>

Age: </td><td> <input type="text" name="age" /> </td></tr><tr><td>

Occupation: </td><td> <input type="text" name="occupation" /></td></tr><tr><td></td>

<td><input type="submit" name="submit" value="Submit" /></td></tr>

</table>

</form>
</body>
</html>
Jan 20, 2011
View noor mohammed 's Profile
here is the html code

<form name="" action="formvalidation.php" method="post">

<table border="0" align="center" cellpadding="2" cellspacing="5"><tr><td>

Name: </td><td> <input type="text" name="name" /> </td></tr><tr><td>

Age: </td><td> <input type="text" name="age" /> </td></tr><tr><td>

Occupation: </td><td> <input type="text" name="occupation" /></td></tr><tr><td></td>

<td><input type="button" name="submit" value="Submit" /></td></tr>

</table>

</form>
Jan 20, 2011