Jump to content

White_Lily

Members
  • Posts

    531
  • Joined

  • Last visited

  • Days Won

    1

Posts posted by White_Lily

  1. If you want multiple errors to appear should there be more than one fault in the form submitted, try using something that displays the errors in a list, like this:

     

    <?php
    
    
    $connect = mysqli_connect("localhost", "web113-social-1", "innov8er", "web113-social-1");
    
    
    if(!$connect){
    die('Connect Error (' . mysqli_connect_errno() . ') '. mysqli_connect_error());
    }
    
    include "conf.php";
    include "functions.php";
    
    
    $error = array();
    
    foreach($_POST as $key => $value){
    if(empty($value) && $value == "undefined")
    $error[] = "Please fill in any blank fields. ".$key.":".$value;
    }
    
    $name = mysqli_real_escape_string($connect, $_POST["name"]);
    $email = mysqli_real_escape_string($connect, $_POST["email"]);
    $username = mysqli_real_escape_string($connect, $_POST["username"]);
    $password = mysqli_real_escape_string($connect, $_POST["password"]);
    $confirmPassword = mysqli_real_escape_string($connect, $_POST["confirmPassword"]);
    
    
    
    $getData = select("*", "users", "username = '$username'", NULL, 1);
    $data = mysqli_fetch_assoc($getData);
    
    if($username == $data["username"])
    $error[] = "That username is already taken, please choose another.";
    
    if($email == $data["email"])
    $error[] = "That email address is already in use.";
    
    if($password != $confirmPassword)
    $error[] = "The passwords you entered do not match.";
    
    if(strlen($username) < 6)
    $error[] = "That username is too short, it should be at least 6 characters long.";
    if(strlen($username) > 30)
    $error[] = "That username is too long, it should be no longer than 30 characters.";
    if(!preg_match('/^[a-zA-Z0-9]+$/', $username))
    $error[] = "Invalid username, there should be no spaces or special charaters, please choose another.";
    
    if(!preg_match('/^(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{6,}$/', $password))
    $error[] = "Invalid password, there should be 1 uppercase and lowercase letter, 1 digit, it must also be a minimum of 6 characters, and a maximum of 30 charaters.";
    
    if(count($error) == 0){
    if(!mkdir($GLOBALS["siteRoot"]."social/users/".$username))
    $error[] = "Could not create your account, either try again later, or contact the webmaster.";
    if(!mkdir($GLOBALS["siteRoot"]."social/users/".$username."/avatars"))
    $error[] = "Could not create your account, either try again later, or contact the webmaster.";
    if(!mkdir($GLOBALS["siteRoot"]."social/users/".$username."/images"))
    $error[] = "Could not create your account, either try again later, or contact the webmaster.";
    if(!mkdir($GLOBALS["siteRoot"]."social/users/".$username."/images/albums"))
    $error[] = "Could not create your account, either try again later, or contact the webmaster.";
    }
    
    if(count($error) > 0){
    for($i = 0; $i < count($error); $i++)
    echo "<li class=\"error\">".$error[$i]."</li>";
    }
    
    $password = hash('sha256', $password);
    
    if(count($error) == 0){
    $regUser = insert("users", "first_name, username, password, directory, email", "'$name', '$username', '$password', '".$GLOBALS["siteRoot"]."social/users/".$username."', '$email'");
    
    if($regUser)
    echo 'correct';
    }
    
    
    ?>
    

     

    and before anyone starts to disagree: yes the foreach($_POST as $key => $value) DOES check to see if the form is empty, should you not believe me click the social network development link in my signature and click "Sign Up" and you will see that it works.

  2. I figured it out, it was the $connect variable being undefined, how I don't know, but all I did was re-type the connection details re-uploaded the file, and the error disappeared and data from the database showed.

  3. Which would most likely suit your site? I find plain text to be boring and not very eye-catching - so a jQuery pop-up box would be better, you could also go the extra mile and make the registration and login forms pop-up boxes aswell, and use jQuery / aJax to validate the forms.

  4. Okay, so I looked back at php.net to see what error checking they use...

     

    <?php
    
    $connect = mysqli_connect("localhost", "username", "password", "database");
    
    if(!$connect){
    die('Connect Error (' . mysqli_connect_errno() . ') '. mysqli_connect_error());
    }
    
    echo 'Success... ' . mysqli_get_host_info($connect) . "\n";
    ?>

     

    Guess what... Still getting an Undefined $connect error... dispite manually typing in the connection settings.

  5. Hi, I have ahd a slight problem with the deprecation of mysql_*() functions, and so are swapping them for mysqli_*() functions, how I have come across an error which states that $connect is undefined.

     

    <?php
    
    $GLOBALS["host"] = "localhost";
    $GLOBALS["user"] = "web113-social-1";
    $GLOBALS["pass"] = "********";
    $GLOBALS["database"] = "***************";
    
    $connect = mysqli_connect($GLOBALS["host"], $GLOBALS["user"], $GLOBALS["pass"], $GLOBALS["database"]);
    ?>

     

    I have compared this against php.net's examples, and this code looks almost exact. I dont know what the problem is. Any help would be appreciated.

     

    - Lily

  6. Although this makes things more difficult and a lot more learning for you, I think most forms should have client AND server side validation. (client side being jQuery & aJax, server-side being PHP), client side is useful so that your users dont have to waste time refilling the form out because theyve got a wrong input, jQuery and aJax validate their inputs as they are typing/clicking.

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