Jump to content

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/215231-easy-question/
Share on other sites

Can we see the rest of your code

 

GT

 

I don't know why you would need all of it, but I guess so.  :shrug:

 

<?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>
';


?>

Link to comment
https://forums.phpfreaks.com/topic/215231-easy-question/#findComment-1119379
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/215231-easy-question/#findComment-1119393
Share on other sites

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..

 

Link to comment
https://forums.phpfreaks.com/topic/215231-easy-question/#findComment-1119398
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.