OOP登录页面错误

时间:2013-08-16 06:39:43

标签: php

使用OOP概念我创建了一个登录页面。我收到此错误: 解析错误:语法错误,第12行的C:\ xampp \ htdocs \ oops \ Register-form \ functions.php中的意外T_PUBLIC

代码

<?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;
     }
  }

如何解决这个问题?

4 个答案:

答案 0 :(得分:3)

这是因为函数在类之外。应该是

<?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;
         }
      }
    }
?>

答案 1 :(得分:2)

你在关闭类之后关闭了你的类并声明了函数。所以在函数声明之前把它关闭并试试这个

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

答案 2 :(得分:1)

使用此

        <?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;
         }
      }
}

你在构造函数后关闭了大括号。所以请结束。

答案 3 :(得分:-1)

所有类函数都应该在类定义中。然后,您可以致电I am doing OOP而不是I end up with OOOOPS

Class  
{
   public function() 
   {
   }
}