PDO,用于注册查询的功能

时间:2017-04-24 02:33:01

标签: php mysql pdo

好日子,乡亲们。我开始学习PHP,并尝试在其中实现PDO类和存储函数,但我一定都错了

    public function register($sid,$sname,$sgender,$sdob,$sbranch, $stell, $position, $salary, $login, $password)
{
   try
   {
       $stmt = $this->db->prepare("INSERT INTO staff(staff_id, staff_name, gender, staff_dob, branch, tell_no, position, salary, staff_login, staff_password) VALUES(:sid,:sname,:sgender,:sdob,:sbranch, :stell, :position, :salary, :login, :password)");

       $stmt->bindparam(":sid", $sid, PDO::PARAM_STR);
       $stmt->bindparam(":sname", $sname, PDO::PARAM_STR);
       $stmt->bindparam(":sgender", $sgender, PDO::PARAM_STR);   
       $stmt->bindparam(":sdob", $sdob, PDO::PARAM_STR); 
       $stmt->bindparam(":sbranch", $sbranch, PDO::PARAM_STR); 
       $stmt->bindparam(":stell", $stell, PDO::PARAM_STR); 
       $stmt->bindparam(":position", $position, PDO::PARAM_STR); 
       $stmt->bindparam(":salary", $salary, PDO::PARAM_INT); 
       $stmt->bindparam(":login", $login, PDO::PARAM_STR); 
       $stmt->bindparam(":password", $password, PDO::PARAM_STR); 

       $stmt->execute(); 

       return $stmt; 
   }

这里是register.php文件

<?php
require_once 'connect.php';
if($staff->is_loggedin()!="")
{
    $staff->redirect('index.html');
}

if(isset($_POST['btn-register']))
{

 $sid = ($_POST['staff_id']);
 $sname = ($_POST['staff_name']);
 $sgender = ($_POST['gender']);
 $sdob = ($_POST['staff_dob']);
 $sbranch = ($_POST['branch']);
 $stell = ($_POST['tel_no']);
 $position = ($_POST['position']);
 $salary = ($_POST['salary']);
 $login = ($_POST['staff_login']);
 $password = ($_POST['staff_password']);


      try
      { 
         $stmt = $link->prepare("SELECT staff_login FROM staff WHERE staff_login=:login");
         $stmt->execute(array(':login'=>$login));
         $row=$stmt->fetch(PDO::FETCH_ASSOC);

         if($row['staff_login']==$login) {
            $error[] = "sorry login already taken !";
         }

         else
         {

            if($staff->register($sid,$sname,$sgender,$sdob,$sbranch, $stell, $position, $salary, $login, $password)) 
            {
                $staff->redirect('register.php?joined');

            }
         }
     }
     catch(PDOException $e)
     {
        echo $e->getMessage();
     }

尝试使用PDO类实现查询,但输入似乎不被接受,也没有进入数据库。检查连接,它有效,试图找出问题所在,你能给我一个建议还是情侣?

0 个答案:

没有答案