-6

using OOP concept I created a login page. I get this error: Parse error: syntax error, unexpected T_PUBLIC in C:\xampp\htdocs\oops\Register-form\functions.php on line 12.

Code

<?php
include("config.php");
class User
{
  //Db Connect
  public function __construct()
  {
    $db=new db_class();
  }
}
  // Registration Process
  public function register_user($name,$username,$password,$email)
  {
     $password=md5($password);
     $sql=mysql_query("select * from login where username='$username' or emailid='$email'");
     if(mysql_num_rows($sql)==0)
     {
        $result=mysql_query("insert into login(username,password,name,emailid) values('$username','$password','$name','$email')");
        return result;
     }
     else
     {
        return false;
     }
  }

How to solve this?

tereško
  • 58,060
  • 25
  • 98
  • 150
user2637639
  • 47
  • 1
  • 3
  • 9

4 Answers4

3

This is because function is outside the class. Should be

<?php
    include("config.php");
    class User
    {
      //Db Connect
      public function __construct()
      {
        $db=new db_class();
      }
      // Registration Process
      public function register_user($name,$username,$password,$email)
      {
         $password=md5($password);
         $sql=mysql_query("select * from login where username='$username' or emailid='$email'");
         if(mysql_num_rows($sql)==0)
         {
            $result=mysql_query("insert into login(username,password,name,emailid) values('$username','$password','$name','$email')");
            return result;
         }
         else
         {
            return false;
         }
      }
    }
?>
i100
  • 4,529
  • 1
  • 22
  • 20
  • 1
    you must have some friends around here.. to be the last one to answer such an obvious thing and to be the only one to get a vote up seconds after the answer was posted.. that's strange.. – mishu Aug 16 '13 at 06:45
2

You have closed your class and declared function after the closing of class.So reove that closing before the function declaration and try this

class User
{
  //Db Connect
  public function __construct()
  {
    $db=new db_class();
  }//End of constructor

  //Here you have closed the class.so i removed the closing and placed it in the end of class.

  // Registration Process
  public function register_user($name,$username,$password,$email)
  {
     $password=md5($password);
     $sql=mysql_query("select * from login where username='$username' or emailid='$email'");
     if(mysql_num_rows($sql)==0)
     {
        $result=mysql_query("insert into login(username,password,name,emailid) values('$username','$password','$name','$email')");
        return result;
     }
     else
     {
        return false;
     }
  }//End of function register_user
}//End of class
웃웃웃웃웃
  • 11,829
  • 15
  • 59
  • 91
1

Use this

        <?php
    include("config.php");
    class User
    {
      //Db Connect
      public function __construct()
      {
        $db=new db_class();
      }

      // Registration Process
      public function register_user($name,$username,$password,$email)
      {
         $password=md5($password);
         $sql=mysql_query("select * from login where username='$username' or emailid='$email'");
         if(mysql_num_rows($sql)==0)
         {
            $result=mysql_query("insert into login(username,password,name,emailid) values('$username','$password','$name','$email')");
            return result;
         }
         else
         {
            return false;
         }
      }
}

you have closed braces after constructor. So please close on end.

Prasannjit
  • 795
  • 4
  • 11
-1

All the class function should be inside the class definition. Then you can call I am doing OOP not I end up with OOOOPS

Class  
{
   public function() 
   {
   }
}
웃웃웃웃웃
  • 11,829
  • 15
  • 59
  • 91
Sahal
  • 4,046
  • 15
  • 42
  • 68