Ok that makes things easier... If its checking validation. Wouldnt it be good if it was with the insert to database bit.. cos what its doing.. Is quickly going through the validation. Then going to the insert database skipping the form..
<?php
//moving the validation
$user="subastic";
$host="localhost";
$password="pass";
$database = "evostation_com_1";
$connection = mysql_connect($host,$user,$password)
or die ("Couldnt connect to server");
$db = mysql_select_db($database,$connection)
or die ("Couldn't select database");
/* check information from the form */
/* set up array of field lables */
$label_array = array ( "nickname" => "Nick Name",
"firstName" => "First Name",
"country" => "Country",
"dob" => "Date of Birth");
foreach ($HTTP_POST_VARS as $key => $value)
{
/* check each field for blank fields */
if ( $value == "" )
{
$blank_array[$key] = "blank";
}
elseif ( ereg("(name)",$key) ) // if key includes "name"
{
if (!ereg("^[A-Za-z' -]{1.50}$",$HTTP_POST_VARS[$key]) )
{
$bad_format[$key] = "bad";
}
}
}
/* if any feilds were not okay, display error message and form */
if (@sizeof($blank_array) > 0 or @sizeof($bad_format) > 0)
{
if (@sizeof($blank_array) > 0)
{
/* display message for missing information */
echo "<b>You didn't fill in one or more required fields. You must
enter:</b><br>";
/* display list of missing information */
foreach($blank_array as $key => $value)
{
echo " {$label_array[$key]}<br>";
}
}
if (@sizeof($bad_format) > 0)
{
/* display message for bad information */
echo "<b>One or more fields have information that appears to be
incorrect. Correct the format for:</b><br>";
/* display list of bad information */
foreach($bad_format as $key => $value)
{
echo " {$label_array[$key]}<br>";
}
}
/* display form */
//end move
if(empty($submit)){
echo "<p><hr>
<form action='createmem.php' method='post'>
<center>
<table width='95%' border='0' cellspacing='0' cellpadding='2'>
<tr><td align='right'><B>{$label_array['nickname']}:</br></td>
<td><input type='text' name='nickname' size='65' maxlength='65'
value='$nickname' > </td>
</tr>
<tr><td align='right'><B>{$label_array['firstName']}:</B></td>
<td><input type='text' name='firstName' size='65' maxlength='65'
value='$firstName' > </td>
</tr>
<tr><td align='right'><B>{$label_array['country']}:</B></td>
<td><input type='text' name='country' size='65' maxlength='65'
value='$country' > </td>
</tr>
<tr><td align='right'<B>{$label_array['dob']}:</B></td>
<td><input type='text' name='dob' size='65' maxlength='65'
value='$dob' > </td>
</tr>
</table>
<p><input type='submit' name=submit value='Submit'>
</form>
</center>";
exit();}
}
else // if data is okay
{
$nickname = trim($nickname);
$nickname = strip_tags($nickname);
$firstName = trim($firstName);
$firstName = strip_tags($firstName);
$country = trim($country);
$country = strip_tags($country);
$dob = trim($dob);
$dob = strip_tags($dob);
$query = "INSERT INTO pk_mem_db (nickname,firstName,country,dob) VALUES
('$nickname','$firstName','$country','$dob')";
$result = mysql_query($query)
or die ("Couldn't execute query.");
echo "New member added to database<br>";
}
?>
ok this may not work.. But play around with it..
<?php
if(empty($submit)){
echo "<p><hr>
<form action='createmem.php' method='post'>
<center>
<table width='95%' border='0' cellspacing='0' cellpadding='2'>
<tr><td align='right'><B>{$label_array['nickname']}:</br></td>
<td><input type='text' name='nickname' size='65' maxlength='65'
value='$nickname' > </td>
</tr>
<tr><td align='right'><B>{$label_array['firstName']}:</B></td>
<td><input type='text' name='firstName' size='65' maxlength='65'
value='$firstName' > </td>
</tr>
<tr><td align='right'><B>{$label_array['country']}:</B></td>
<td><input type='text' name='country' size='65' maxlength='65'
value='$country' > </td>
</tr>
<tr><td align='right'<B>{$label_array['dob']}:</B></td>
<td><input type='text' name='dob' size='65' maxlength='65'
value='$dob' > </td>
</tr>
</table>
<p><input type='submit' name=submit value='Submit'>
</form>
</center>";
exit();}
}
else // if data is okay
{
//moving the validation
$user="subastic";
$host="localhost";
$password="pass";
$database = "evostation_com_1";
$connection = mysql_connect($host,$user,$password)
or die ("Couldnt connect to server");
$db = mysql_select_db($database,$connection)
or die ("Couldn't select database");
/* check information from the form */
/* set up array of field lables */
$label_array = array ( "nickname" => "Nick Name",
"firstName" => "First Name",
"country" => "Country",
"dob" => "Date of Birth");
foreach ($HTTP_POST_VARS as $key => $value)
{
/* check each field for blank fields */
if ( $value == "" )
{
$blank_array[$key] = "blank";
}
elseif ( ereg("(name)",$key) ) // if key includes "name"
{
if (!ereg("^[A-Za-z' -]{1.50}$",$HTTP_POST_VARS[$key]) )
{
$bad_format[$key] = "bad";
}
}
}
/* if any feilds were not okay, display error message and form */
if (@sizeof($blank_array) > 0 or @sizeof($bad_format) > 0)
{
if (@sizeof($blank_array) > 0)
{
/* display message for missing information */
echo "<b>You didn't fill in one or more required fields. You must
enter:</b><br>";
/* display list of missing information */
foreach($blank_array as $key => $value)
{
echo " {$label_array[$key]}<br>";
}
}
if (@sizeof($bad_format) > 0)
{
/* display message for bad information */
echo "<b>One or more fields have information that appears to be
incorrect. Correct the format for:</b><br>";
/* display list of bad information */
foreach($bad_format as $key => $value)
{
echo " {$label_array[$key]}<br>";
}
}
/* display form */
//end move
$nickname = trim($nickname);
$nickname = strip_tags($nickname);
$firstName = trim($firstName);
$firstName = strip_tags($firstName);
$country = trim($country);
$country = strip_tags($country);
$dob = trim($dob);
$dob = strip_tags($dob);
$query = "INSERT INTO pk_mem_db (nickname,firstName,country,dob) VALUES
('$nickname','$firstName','$country','$dob')";
$result = mysql_query($query)
or die ("Couldn't execute query.");
echo "New member added to database<br>";
}
?>
Now its not tested of course.. But this should know display the form.. Just fix a few things..