求php用面向对象实现用户注册的完整代码
我试过,用面向对象写的,但是用户注册的信息项有五六个,参数似乎多了不行我的代码如下:
include("conn_db.php");//连接数据库
if($_SERVER['REQUEST_METHOD']=='POST')//判断提交的数据是否是POST方式传来的
{
$user_name=$_POST['user_name'];
$user_pw=$_POST['user_pw'];
$user_sex=$_POST['user_sex'];
$user_phone=$_POST['user_phone'];
$user_address=$_POST['user_address'];
$user_email=$_POST['user_email'];
}
require("function.php");//调用类
$register=new register();//类的实例化
if($user_pw=="" || $user_name==""){
echo "<script>alert('用户名或密码不能为空!!');history.go(-1);</script>";
}
else{
$register->insert_register($user_name,$user_pw,$user_sex,$user_phone,$user_address,$user_email);//调用类中的insert_register方法
echo "注册成功";
//echo "<script>alert('注册成功');location.href='main_net.php';</script>";
}
创建对象和方法
class register{
//定义类的成员
var $insert_register;
}
function insert_register($user_name,$user_pw,$user_sex,$user_phone,$user_address,$user_email){
$sql="insert into bbs(user_name,user_pw,user_sex,user_phone,user_address,user_email) values
('$user_name','$user_pw','$user_sex','$user_phone','$user_address','$user_email')";
$result=mysqli_query($sql);
}
下面是报错
Fatal error: Call to undefined method register::insert_register() in D:\PHPtable\WEB\register.php on line 19
求大神指教,最好是全部完整代码供我参考
[此贴子已经被作者于2017-8-8 15:12编辑过]