marcus Posted December 26, 2006 Share Posted December 26, 2006 I am making a user registration and it just checks to see if all the fields are filled in. But if they aren't then the file would echo off an error.[code]<?php include('header.php'); ?><?php $act = $_POST[act]; if(!isset($act)){ echo "<table border=0 cellspacing=3 cellpadding=2>\n"; echo "<form name=reg method=post action='".$_SERVER[PHP_SELF]."'>\n"; echo "<tr><td class=gbr>Username:<td class=gbr><input type=text name=username>\n"; echo "<tr><td class=gbr>Password:<td class=gbr><input type=password name=pass>\n"; echo "<tr><td class=gbr>Confirm:<td class=gbr><input type=passowrd name=pass2>\n"; echo "<tr><td class=gbr>Email:<td class=gbr><input type=text name=email>\n"; echo "<tr><td class=gbr>Confirm:<td class=gbr><input type=text name=email2>\n"; echo "<tr><td class=gbr>Birthday:<td class=gbr> <select name=month> <option value=January>January <option value=February>February <option value=March>March <option value=April>April <option value=May>May <option value=June>June <option value=July>July <option value=August>August <option value=September>September <option value=October>October <option value=November>November <option value=December>December </select>\n<select name=day>\n"; for($i=1; $i<32; $i++){ echo "<option value=$i>$i</option>\n"; }; echo "</select>\n"; echo "<select name=year>\n"; for($i=1900; $i<1994; $i++){ echo "<option value=$i>$i</option>\n"; }; echo "</select>\n"; echo "<tr><td colspan=2><input type=submit value='".Register."'> <input type=reset value='".Reset."'>\n"; echo "<input type=hidden name=act value=register>\n"; echo "</form></table>\n"; } if($act == register){ $username = $_POST[username]; $pass = $_POST[pass]; $pass2 = $_POST[pass2]; $email = $_POST[email]; $email2 = $_POST[email2]; $month = $_POST[month]; $day = $_POST[day]; $year = $_POST[year]; if(isset($username) && isset($pass) && isset($pass2) && isset($email) && isset($email2)){ if($pass != $pass2){ echo "<b>Your confirmation password is not the same as your password!</b><br>"; } if($email != $email2){ echo "<b>Your confirmation email is no the same as your email!</b><br>"; } }else { echo "Please fill in all the fiedls!"; } }?><?php include('footer.php'); ?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/31891-error-messages-not-showing/ Share on other sites More sharing options...
Psycho Posted December 26, 2006 Share Posted December 26, 2006 if($act == register){ Quote Link to comment https://forums.phpfreaks.com/topic/31891-error-messages-not-showing/#findComment-148017 Share on other sites More sharing options...
marcus Posted December 26, 2006 Author Share Posted December 26, 2006 That's what I have. Still isn't working. Quote Link to comment https://forums.phpfreaks.com/topic/31891-error-messages-not-showing/#findComment-148019 Share on other sites More sharing options...
bljepp69 Posted December 26, 2006 Share Posted December 26, 2006 No. That's the problem line. Does $act=='register' or $act==$register maybe? Quote Link to comment https://forums.phpfreaks.com/topic/31891-error-messages-not-showing/#findComment-148020 Share on other sites More sharing options...
marcus Posted December 26, 2006 Author Share Posted December 26, 2006 Nope :/ Quote Link to comment https://forums.phpfreaks.com/topic/31891-error-messages-not-showing/#findComment-148027 Share on other sites More sharing options...
wildteen88 Posted December 26, 2006 Share Posted December 26, 2006 Try this:[code]<?phpif(isset($_POST['act']) && $_POST['act'] == 'register'){ $errors = ''; foreach($_POST as $key => $value) { if($key == 'pass' || $key == 'email') { $k = $key . '2'; if(empty($_POST[$key]) || $_POST[$key] != $_POST[$k]) { $field = (($key == 'pass') ? 'passwords' : 'email addresses'); $errors[] = 'The ' . $field . ' do not match'; } } elseif(isset($_POST[$key]) && empty($_POST[$key])) { if($key != 'pass2' && $key != 'email2') { $errors[] = 'Please fill in the ' . $key . " field<br />\n"; } } } if(is_array($errors)) { echo "Unable to submit the form, due to the following errors:<br /><ul>\n"; foreach($errors as $error) { echo ' <li>' . $error . "</li>\n"; } echo "</ul>\n"; }}echo <<<HTML<form name="reg" method="post" action="{$_SERVER['PHP_SELF']}"> <table border="0" cellspacing="3" cellpadding="2"> <tr> <td class="gbr">Username:</td> <td class="gbr"><input type="text" name="username"></td> </tr> <tr> <td class="gbr">Password:</td> <td class="gbr"><input type="password" name="pass"></td> </tr> <tr> <td class="gbr"><i>Confirm:</i></td> <td class="gbr"><input type="password" name="pass2"></td> </tr> <tr> <td class="gbr">Email:</td> <td class="gbr"><input type="text" name="email"></td> </tr> <tr> <td class="gbr"><i>Confirm:</i></td> <td class="gbr"><input type="text" name="email2"></td> </tr> <tr> <td class="gbr">Birthday:</td> <td class="gbr"> <select name="month"> <option value="January">January</option> <option value="February">February</option> <option value="March">March</option> <option value="April">April</option> <option value="May">May</option> <option value="June">June</option> <option value="July">July</option> <option value="August">August</option> <option value="September">September</option> <option value="October">October</option> <option value="November">November</option> <option value="December">December</option> </select> <select name="day">HTML; for($i = 1; $i < 32; $i++) { echo ' <option value="' . $i . '">' . $i . "</option>\n "; } echo " </select>\n"; echo " <select name=\"year\">\n"; for($i = 1900; $i < 1994; $i++) { echo ' <option value="' . $i . '">' . $i . "</option>\n"; } echo <<<HTML </select> </td> </tr> <tr> <td colspan="2"> <input type="submit" value="Register"> <input type="reset" value="Reset"> <input type="hidden" name="act" value="register"> </td> </tr> </table></form>HTML;?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/31891-error-messages-not-showing/#findComment-148033 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.