-1

This script only displays the title with a blank page. I test it without any data.

I get these errors:

Notice: Undefined variable: databse in C:\Winginx\home\localhost\public_html\registration.php on line 50

Notice: Trying to get property of non-object in C:\Winginx\home\localhost\public_html\registration.php on line 50

Fatal error: Call to a member function findOne() on a non-object in C:\Winginx\home\localhost\public_html\registration.php on line 54

<?php
session_start();

if($_POST['submit']){
    $ScName=strip_tags($_POST['ScName']);
    $fname=strip_tags($_POST['fname']);
    $lname=strip_tags($_POST['lname']);
    $email=strip_tags($_POST['email']);
    $password=strip_tags($_POST['password']);
    $password2=strip_tags($_POST['password2']);
    
    $error = array();
 
        if(empty($email) or !filter_var($email,FILTER_SANITIZE_EMAIL))
        {
          $error[] = "Email id is empty or invalid";
        }
        if(empty($password)){
          $error[] = "Please enter password";
        }
        if(empty($password2)){
          $error[] = "Please enter Confirm password";
        }
        if($password != $password2){
           $error[] = "Password and Confirm password are not matching";
        }
        if(empty($fname)){
            $error[] = "Enter first name";
        }
        if(empty($lname)){
            $error[] = "Enter last name";
        }
        
        if(count($error == 0)){
            //database configuration
            $host = 'localhost';
            $database_name = 'mongo1';
            $database_user_name = '';  
            $database_password = '';  
            
             $connection=new Mongo('localhost');
             
             if($connection){
 
                 //connecting to database
                 $database=$connection->$database_name;
 
                 //connect to specific collection
                 $collection=$databse->user;
 
                 $query=array('email'=>$email);
                 //checking for existing user
                 $count=$collection->findOne($query);
 
                 if(!count($count)){
                     //Save the New user
                     $user=array('fname'=>$fname,'lname'=>$lname,'ScName'=>$ScName,'email'=>$email,'password'=>md5($password),'password'=>$password2);             
                     $collection->save($user);
                     echo "You are successfully registered.";
                 }else{
                     echo "Email is already existed.Please register with another Email id!.";
                 }
 
             }else{
 
                  die("Database are not connected");
             }
 
        }else{
            //Displaying the error
            foreach($error as $err){
                echo $err.'</br>';
            }
        }
        }

?>

<html>
    <head>
        <title>
            Registration
        </title>
    </head>
 <body>
<form action="registration.php" method="POST">
Screen Name:
<input type="text" id="ScName" name="ScName"  /></br></br>
First Name:
<input type="text" id="fname" name="fname"  /></br></br>
Last Name:
<input type="text" id="lname" name="lname"  /></br></br>
Email:
<input type="text" id="email" name="email"  /></br></br>
Password:
<input type="password" id="password" name="password" />  </br></br>
Confirm Password:
<input type="password" id="password2" name="password2" />  </br></br>

<input  name="submit" id="submit" type="submit" value="register" />
</form>
    </body>
</html>
Community
  • 1
  • 1
ORYON100
  • 103
  • 1
  • 12
  • 1
    i thought it had become a generic expression to just say guys but my apologies. and because as part of my test i submit an empty form, i would expect to see all the errors – ORYON100 Apr 19 '15 at 00:43
  • this is not enough for someone to provide you any answer, show the code that is calling the php script to see if anything is being passed to it. You have an if statement on top that will work if parameter 'register' was passed to it, otherwise, you will get nothing. – faljbour Apr 19 '15 at 01:18
  • @faljbour i have added the html file on the same document, please note they are actually 2 seperate files, the html and the php. just made it like this to make my code clear. thanks for the help – ORYON100 Apr 19 '15 at 01:49
  • you should definitely add `ini_set('display_errors',1);error_reporting(E_ALL);` at the top of your script and see what happens – Félix Adriyel Gagnon-Grenier Apr 19 '15 at 01:51
  • 1
    thanks @Félix Gagnon-Grenier i added the code and this is what i got: Notice: Undefined variable: databse in C:\Winginx\home\localhost\public_html\registration.php on line 50 Notice: Trying to get property of non-object in C:\Winginx\home\localhost\public_html\registration.php on line 50 Fatal error: Call to a member function findOne() on a non-object in C:\Winginx\home\localhost\public_html\registration.php on line 54 – ORYON100 Apr 19 '15 at 02:03
  • and here is lines 50 to 54 $collection=$databse->user; $query=array('email'=>$email); //checking for existing user $count=$collection->findOne($query); – ORYON100 Apr 19 '15 at 02:05

1 Answers1

1
 $collection=$databse->user;

here. write

 $collection=$database->user;

instead

that's what

Notice: Undefined variable: databse

Tells you

Then when you count the errors, the parenthesis is on the wrong side of the two equal signs. It should be like this

if (count($error) == 0)

And not

if (count($error == 0))
  • i deserve a slap for that one lol thanks. ok now its working after but it goes on to add the data without doing the checks. i entered the data on my form with a lot of blanks and it went straight to my database without doing the error checks :( – ORYON100 Apr 19 '15 at 02:17