Recur
Recur

Reputation: 1428

Echo not displaying inside a div but worked outside of it

I'm currently making a webpage and I have run in to some problems with echo being inside a div container.

My website is currently setup like this: index.php has the header and a navigation pane on the left side. and there is a bodycontent div that will load in different pages depending on what is clicked. I previously had the following code in my index.php right before my bodycontent div:

<?php   
//set the variables
$username   = isset($_POST['username']) ? $_POST['username'] : '';
$email      = isset($_POST['email']) ? $_POST['email'] : '';
$password   = isset($_POST['password']) ? $_POST['password'] : '';
$step       = isset($_POST['step']) ? $_POST['step'] : '1';

//validation        
if($step=='2'){
    if($username == '' || strlen($username)==0){
        echo 'username can not be blank<br/>';
    }
    if(filter_var($email, FILTER_VALIDATE_EMAIL) == false){     
        $errors[] = 'invalid email address<br/>';
    }    
    if($password == '' || strlen($password)<=4){
        $errors[] = 'password can not be blank or less than 4 characters<br/>';
    }
    $username=mysql_real_escape_string(trim($username));
    $email=mysql_real_escape_string(trim($email));
    $password=md5(mysql_real_escape_string(trim($password)));
    //mysql queries
    if(empty($errors)){
        //do something      
        $query = "
            INSERT INTO user
            (email, username, password, user_level)
            VALUES
            ('$email', '$username', '$password', '1')";
        $result = mysql_query($query) or die ('error: '. mysql_error());
        echo 'new user registered!';
        $step='2';
    }
    else{       
        //error output
        foreach($errors as $errors)
        echo $errors;
        $step='1';
    }

}
if($step=='1'){
?>

I decided to move this piece of code in my registration.php page so the index.php looks cleaner for me. However, ever since I moved the code from index.php to registration.php the echos are not displaying. If you need more code I will gladly post some more.. I don't want to overwhelm right now.

Upvotes: 0

Views: 579

Answers (1)

wabism
wabism

Reputation: 46

I noticed in your final foreach loop:

foreach($errors as $errors) is missing an opening bracket;

foreach($errors as $error) {
 // instructions
}

Upvotes: 3

Related Questions