I think I've jumped off the long board in the shallow end, LoL. I've written what I think to be a pretty decent piece of code. I've got it checking for mistakes. Now, I can't seem to figure out how to make a check to see if all is good so I can move onto the mysql checks. Any advise would be helpful.
Is there an easier way to do this. I mean the way I am trying to do it?? I just want the error next to the form input. I want to do a check to see if all fields are filled and met. Then I want to check mysql for duplicate name, and such. I'm pretty sure I could write the code for that. But I need something small that checks one function before I can get to the mysql phase. Am I making any sense?
<?php
/* ============================= Div, Form, Table =============================== */
echo '<div class="form"> <form action="index.php" method="POST"> <table class="submit"> ';
/* ============================= Row 1 (Username) =============================== */
echo '<tr><td>Username:</td> <td><input name="name" type="text" style="width:150px" /> </td>';
echo '<td class="three">';
if ( isset( $_POST["submit"] ) )
{
$errors = '';
// ( $index , $label, $required , $min , $max )
$errors .= check( "name" , "username" , 1 , 5 , 14 );
if(!empty($errors)) {echo $errors;};
echo '</td> </tr>';
/* ============================= Row 2 (Password) ================================ */
echo '<tr> <td>Password:</td> <td><input name="password" type="password" style="width: 150px" /> </td>';
echo '<td class="three">';
if ( isset( $_POST["submit"] ) )
{
$errors = '';
// ( $index , $label, $required , $min , $max )
$errors .= check( "password" , "password" , 1 , 5 , 12 );
if(!empty($errors)) {echo $errors;};
}
echo '</td> </tr>';
/* ============================= Row 3 (Password1) =============================== */
echo '<tr> <td> Password:</td> <td><input name="password1" type="password" style="width: 150px" /> </td>';
echo '<td class="three">';
if ( isset( $_POST["submit"] ) )
{
$errors = '';
// ( $index , $label, $required , $min , $max )
$errors .= check( "password" , "password1" , 1 , 5 , 12 );
if(!empty($errors)) {echo $errors;};
}
echo '</td></tr>';
/* ============================= Row 4 (email) =================================== */
echo '<tr> <td> Email Address: </td> <td><input name="email" type="text" style="width:150px" /> </td>';
echo '<td class="three">';
if ( isset( $_POST["submit"] ) )
{
$errors = '';
// ( $index , $label, $required , $min , $max )
$errors .= check( "email" , "email" , 1 , 8 , 50 );
if(!empty($errors)) {echo $errors;};
}
echo '</td> </tr>';
/* ============================= Row 5 (Expansion) =============================== */
echo '<tr> <td> Expansion: </td> <td> <select name="client" style="width:155px">
<option value="0">World of WarCraft</option>
<option value="1">Burning crusade </option>
<option value="2">Wrath of the LichKing </option> </select> </td> </tr>';
/* ============================= Row 6 (Verification) ============================ */
echo '<tr>
<td> Verification image: </td> <td> <img src="inc/" alt="" /> </td>
<td class="three"> </td> </tr>';
/* ============================= Row 7 (Code) ===================================== */
echo '<tr> <td> Enter answer: </td> <td> <input name="code" style="width:150px" maxlength="5" /> </td>';
echo '<td class="three">';
if ( isset( $_POST["submit"] ) )
{
$errors = '';
// ( $index , $label, $required , $min , $max )
$errors .= check( "code" , "code" , 1 , 1 , 2 );
if(!empty($errors)) {echo $errors;};
}
echo '</td> </tr>';
/* ============================= Row 8 (Submit) =================================== */
echo '<tr> <td class="submit" colspan="3"> <input name="submit" type="submit" value="Register" /> </td> </tr>';
/* ============================= Table / Form / Div end =========================== */
echo '</table></form></div>';
/* ============================= Wc3 cert ========================================= */
echo '<div class="wc3"><ul>';
echo '<li> <a href="http://getmangos.org/" target="_blank"> Mangos </a></li>';
echo '<li> <a href="http://www.trinitycore.org/forum/" target="_blank">TrinityCore2</a></li>';
echo '<li> <a href="http://validator.w3.org/check?uri=referer" target="_blank"><img src="http://www.w3.org/Icons/valid-xhtml10-blue" alt="Valid XHTML 1.0 Transitional" height="31px" width="88px" style="border:0" /></a></li>';
echo '<li> <a href="http://jigsaw.w3.org/css-validator/check/referer" target="_blank"><img style="border:0;width:88px;height:31px" src="http://jigsaw.w3.org/css-validator/images/vcss-blue" alt="Valid CSS!" /></a></li>';
echo '</ul> </div>';
/* ============================= Starting checks ================================== */
function check( $index , $label, $required , $min , $max, )
{
$errors = '';
$look = false;
$value = isset( $_POST[$index] ) ? $_POST[$index] : null ;
if ( $required AND empty( $value ) )
$errors .= $label . ' is empty<br />';
else {
if ( strlen( $value ) > $max ) $errors .= $label . ' is longer then' . $max;
elseif ( strlen( $value ) < $min ) $errors .= $label . ' is shorten then' . $min;
}
return $errors;
}
?>
:eek: