Having a problem in php

<?php
if (isset ($_POST['signup'])){
	$email=$_POST['email'];
	$password=$_POST['password'];
	$username=$_POST['username'];
	$error='';


if(empty($username) or empty($email) or empty($password)){
	$error = 'all information are required';
	}
	 else {
	$email =  $getFromU->checkInput($email);
	$password =  $getFromU->checkInput($password);
	$username =  $getFromU->checkInput($username);
		
		if(!filter_var($email)){
	$error ='invalid email format';
		}
		else if(strlen($password)<5){
			$error='password is to short';
		}
		
		else{
			if($getFromU->checkEmail($email)===true){
				$error='email already exist';
			}
			else if(!empty($username)){
                if(strlen($username) > 20){
                    $error = "Username must be in between 6 to 20 characters";
                } 
                else if($getFromU->checkUsername($username) === true ){
                    $error = "username  already taken";
                }
			else{
				$getFromU->register($email,$username,$password);
			//$getFromU->create('users',array('email'=>$email,'password'=>md5($password),'username'=>$username,'profileImage' => 'images\defaultprofileimage.png'));

        $_SESSION['user_id'] = $user_id;


						header("location: home.php");					
							
					}
		}

				}
			}

		}
?>
public function register($email,$password,$username)
     {
         $stmt = $this->pdo->prepare("INSERT INTO `users` ( `email`,`password`, `username`,`profileImage`)
                          VALUES( :email, :password, :username,'images/defaultprofileimage.png') ");
         $stmt->bindParam(":email", $email, PDO::PARAM_STR);
         $stmt->bindParam(":password", md5($password), PDO::PARAM_STR);
         $stmt->bindParam(":username", $username, PDO::PARAM_STR);

        $stmt->execute();
         $user_id = $this->pdo->lastInsertId();
        $_SESSION['user_id'] = $user_id;
    }

error i having

don’t ask for properties on non-objects then.

so what should i do because i try every thing but the problem is stilll the same

you are accessing a property named username anywhere, the file and line number are shown, so have a look there. But it’s not in code shown.

https://github.com/ayusharma123456/ayush see your self the whole project

where is session_start();? I don’t see this code in your example, so how do you implement a session or where do you begin and handle the session?

hey john you can see my project its in session start in it https://github.com/ayusharma123456/ayush

personally i won’t download and open any zip file. just post the code here, file and line are shown in the error message.

public function register($email,$password,$username)
{
$stmt = $this->pdo->prepare(“INSERT INTO users ( email,password, username,profileImage)
VALUES( :email, :password, :username,‘images/defaultprofileimage.png’) “);
$stmt->bindParam(”:email”, $email, PDO::PARAM_STR);
$stmt->bindParam(":password", md5($password), PDO::PARAM_STR);
$stmt->bindParam(":username", $username, PDO::PARAM_STR);

    $stmt->execute();
     $user_id = $this->pdo->lastInsertId();
    $_SESSION['user_id'] = $user_id;
}
<?php if (isset ($_POST['signup'])){ $username=$_POST['username']; $password=$_POST['password']; $email=$_POST['email']; $error=''; if(empty($username) or empty($email) or empty($password)){ $error = 'all information are required'; } else { $email = $getFromU->checkInput($email); $password = $getFromU->checkInput($password); $username = $getFromU->checkInput($username); if(!filter_var($email)){ $error ='invalid email format'; } else if(strlen($password)<5){ $error='password is to short'; } else{ if($getFromU->checkEmail($email)===true){ $error='email already exist'; } else if(!empty($username)){ if(strlen($username) > 20){ $error = "Username must be in between 6 to 20 characters"; } else if($getFromU->checkUsername($username) === true ){ $error = "username already taken"; } else{ $getFromU->register($email,$username,$password); //$getFromU->create('users',array('email'=>$email,'password'=>md5($password),'username'=>$username,'profileImage' => 'images\defaultprofileimage.png')); $_SESSION['user_id'] = $user_id; header("location: home.php"); } } } } } ?>
<div id="info3">Name</div>
            <input type="text" name="username" style="width:350px; height:30px;"><br><br>
        </div>   

            <div class="form-group">
            <div id="info3" >Email Address</div>
            <input type="email" name="email" style="width:350px; height:30px;"/> <br><br>
        </div>  

        <div class="form-group">
            <div id="info3">Password</div>
            <input type="password" name="password" style="width:350px; height:30px;"/><br><br>
        </div>

        <div class="form-group">
       <input type="submit" name="signup" Value="Signup">
        </div>
<?php if(isset($error)){ echo'
  • '.$error.'
  • '; } ?>

    so any advice so far

    look at the line within the file from the error message.

    ido that but the error is about the system could able to find the file in the table because it did’nt exist in it so something is wrong with the registration code so can you tell me how an i rewrite this to fix it

    so what does this mean? What’s the error message?

    Show me line 35 of header.php

    $user_id = @$_SESSION[‘user_id’];
    $user = $getFromU->userData($user_id);

    line 35
    <labelclass=“drop-label” for=“drop-wrap1”><?php echo $user->username;?>

    <labelclass=“drop-label” for=“drop-wrap1”><?php echo $user->username;?>

    Sponsor our Newsletter | Privacy Policy | Terms of Service