This is my code:
[code=php]
<?php
//start a session
session_start() ;
$errors = NULL;
$firstname = $_POST["firstname"];
//validate fields
function validate_firstn ame($firstname)
{
global $errors;
if (ereg("^[A-Z][a-z]+", $firstname))
{
return true;
}
else
{
$errors = $errors + "The first name entered is invalid.<br />e.g. Daniel<br /><br />";
return false;
}
}
//produce validation errors
if (validate_first name($firstname ) == true)
{
include("header .php");
include("notmem berbar.php");
echo "<div class=\"content \">";
echo "<h1>Detail s Are Valid</h1>";
echo "<p>Well done</p>";
include("bottom .php");
return true;
}
else if (validate_first name($firstname ) == false)
{
include("header .php");
include("notmem berbar.php");
echo "<div class=\"content \">";
echo "<h1>Detail s Are Invalid</h1>";
echo "<p>$errors </p>";
include("bottom .php");
return false;
}
?>
[/code]
[Please use CODE tags when posting source code. Thanks! --pbmods]
I'm having massive trouble printing out that variable $errors.
Any ideas? - I got an idea that its a very simple error im making.
Thanks.
William.
[code=php]
<?php
//start a session
session_start() ;
$errors = NULL;
$firstname = $_POST["firstname"];
//validate fields
function validate_firstn ame($firstname)
{
global $errors;
if (ereg("^[A-Z][a-z]+", $firstname))
{
return true;
}
else
{
$errors = $errors + "The first name entered is invalid.<br />e.g. Daniel<br /><br />";
return false;
}
}
//produce validation errors
if (validate_first name($firstname ) == true)
{
include("header .php");
include("notmem berbar.php");
echo "<div class=\"content \">";
echo "<h1>Detail s Are Valid</h1>";
echo "<p>Well done</p>";
include("bottom .php");
return true;
}
else if (validate_first name($firstname ) == false)
{
include("header .php");
include("notmem berbar.php");
echo "<div class=\"content \">";
echo "<h1>Detail s Are Invalid</h1>";
echo "<p>$errors </p>";
include("bottom .php");
return false;
}
?>
[/code]
[Please use CODE tags when posting source code. Thanks! --pbmods]
I'm having massive trouble printing out that variable $errors.
Any ideas? - I got an idea that its a very simple error im making.
Thanks.
William.
Comment