-6

使用 OOP 概念我创建了一个登录页面。我收到此错误: Parse error: syntax error, unexpected T_PUBLIC in C:\xampp\htdocs\oops\Register-form\functions.php on line 12

代码

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

4 回答 4

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;
         }
      }
    }
?>
于 2013-08-16T06:44:24.360 回答
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
于 2013-08-16T06:42:22.437 回答
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;
         }
      }
}

你在构造函数之后有大括号。所以请关闭。

于 2013-08-16T06:43:05.893 回答
-1

所有的类函数都应该在类定义中。然后你可以打电话I am doing OOPI end up with OOOOPS

Class  
{
   public function() 
   {
   }
}
于 2013-08-16T06:50:33.007 回答