Spring Posted October 5, 2010 Share Posted October 5, 2010 Right now I'm working on a simple register form and I have included the theme. I set up a div and positioned the div below the register form to output any error in red text. If I were to use code like this if(empty($_POST['username']) || empty($_POST['password']) || empty($_POST['email']) || empty($_POST['Veremail'])){ $required_info = "All three fields are required to continue!"; } It will not work, because I don't have a die(); or end(); function, so it will display: " All three fields are required to continue! and You have been successfully registered! " BUT IT'S IN THE CORRECT PLACE UNDER THE FORM WHERE I PLACED THE DIV. So I made this change if(empty($_POST['username']) || empty($_POST['password']) || empty($_POST['email']) || empty($_POST['Veremail'])){ $required_info = die("All three fields are required to continue!"); } and it worked fine, but now, the words are not positioned under the form, but at the bottom of the page, I'm wondering how I would end that script, but align the text so it displays underneath the form, and not at the bottom of the page? If you don't understand ask me please. Quote Link to comment https://forums.phpfreaks.com/topic/215231-easy-question/ Share on other sites More sharing options...
GalaxyTramp Posted October 5, 2010 Share Posted October 5, 2010 Can we see the rest of your code GT Quote Link to comment https://forums.phpfreaks.com/topic/215231-easy-question/#findComment-1119378 Share on other sites More sharing options...
Spring Posted October 5, 2010 Author Share Posted October 5, 2010 Can we see the rest of your code GT I don't know why you would need all of it, but I guess so. <?php include "registertheme.php"; include "database.php"; //Check to see if someone pressed submit to start the whole script.. if(isset($_POST['go'])){ //Check if all three fields are submitted. if(empty($_POST['username']) || empty($_POST['password']) || empty($_POST['email']) || empty($_POST['Veremail'])){ $required_info = "All three fields are required to continue!"; } //Makes sure that the email field has a "@" if( strpos($_POST['email'], '@') || strpos($_POST['Veremail'], '@') === false ){ $no_at = "Your email address is missing '@'"; } $check ='SELECT username FROM account_info WHERE username ="'.strtolower($_POST['username']).'"'; $result = mysql_query($check); //checks the database to make sure that a username doesn't repeat if (mysql_num_rows($result) != 0) { $exist_username = "Username already exists!"; } $check2 = 'SELECT email FROM account_info WHERE email = "' . $_POST['email'] . '"'; $result2 = mysql_query($check2); //checks to see if email address is repeated if (mysql_num_rows($result2) != 0) { $exist_email = "Email address already exists!"; } //inserts username into database if all of the fields above are correct. else{ $sql = 'INSERT INTO account_info ( username, password, email, verify_email ) VALUES ( "' .strtolower($_POST['username']). '", "' .strtolower($_POST['password']) . '", "' .$_POST['email'] .'", "'. $_POST['Veremail'] .'" )'; $register = mysql_query($sql); if (!$register) { exit("The query did not go through, lol'd"); } else { $registered = 'You\'ve been successfully registered!'; } } } echo' <html> <div id="error"> ' . @$no_at . @$required_info . @$exist_username . @$exist_email . @$registered . ' </div> </html> '; ?> Quote Link to comment https://forums.phpfreaks.com/topic/215231-easy-question/#findComment-1119379 Share on other sites More sharing options...
Spring Posted October 5, 2010 Author Share Posted October 5, 2010 Anyone? Quote Link to comment https://forums.phpfreaks.com/topic/215231-easy-question/#findComment-1119386 Share on other sites More sharing options...
sphinx Posted October 5, 2010 Share Posted October 5, 2010 You want to make text bold? Quote Link to comment https://forums.phpfreaks.com/topic/215231-easy-question/#findComment-1119390 Share on other sites More sharing options...
Spring Posted October 5, 2010 Author Share Posted October 5, 2010 You want to make text bold? Looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooool no I want to position the errors. Quote Link to comment https://forums.phpfreaks.com/topic/215231-easy-question/#findComment-1119391 Share on other sites More sharing options...
KevinM1 Posted October 5, 2010 Share Posted October 5, 2010 Simply put, your form processing logic is off. You need to see if errors have actually been encountered before attempting to insert field values. Right now, you really only see if an email address exists before merrily inserting data. In short, go through your script by hand. Take note of exactly what your conditionals are doing (hint: it's not what you want them to do). Let's say username is empty. You create an error message, but do you actually test to see if that error condition exists before going to the db? No. That's one example of many in your script. Also, don't use the '@' when outputting. Next to people using 'global', it's probably the most misused part of PHP. Quote Link to comment https://forums.phpfreaks.com/topic/215231-easy-question/#findComment-1119393 Share on other sites More sharing options...
Spring Posted October 5, 2010 Author Share Posted October 5, 2010 Simply put, your form processing logic is off. You need to see if errors have actually been encountered before attempting to insert field values. Right now, you really only see if an email address exists before merrily inserting data. In short, go through your script by hand. Take note of exactly what your conditionals are doing (hint: it's not what you want them to do). Let's say username is empty. You create an error message, but do you actually test to see if that error condition exists before going to the db? No. That's one example of many in your script. Also, don't use the '@' when outputting. Next to people using 'global', it's probably the most misused part of PHP. Thanks, I'll look it over a few times.. Quote Link to comment https://forums.phpfreaks.com/topic/215231-easy-question/#findComment-1119398 Share on other sites More sharing options...
Spring Posted October 5, 2010 Author Share Posted October 5, 2010 Got it to work. Quote Link to comment https://forums.phpfreaks.com/topic/215231-easy-question/#findComment-1119410 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.