Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- require_once('database.php');
- $obj = new Database;
- $obj->getConnection();
- class Member{
- private $username;
- private $userpassword;
- public function regist(){
- if(isset($_POST['action'])&&$_POST['action']=='insert'){
- try{
- $sql = "INSERT INTO userData(username,password)VALUES(:username,:password)";
- $stmh = $obj->prepare($sql);//the error occour here
- $stmh -> bindValue('username',$_POST['username'],PDO::PARAM_STR);
- $stmh -> bindValue('password',password_hash($_POST['userpassword'],PASSWORD_DEFAULT),PDO::PARAM_STR);
- $stmh -> execute();
- echo "登録しました<br>";
- }catch(PDOExcetion $e){
- echo "error ".$e->getMessage();
- }
- }
- }
- public function login(){
- $sql = "SELECT * FROM userData WHERE username=:usrname";
- $stmh =$obj->prepare($sql);//the error occour here
- $stmh ->bindValue(':usrname',$_POST['username'],PDO::PARAM_STR);
- $stmh->execute();
- $row = $stmh->fetch(PDO::FETCH_ASSOC);
- if($row['username'] == false){
- echo"login fail";
- exit;
- }
- $hash = $row['password'];
- if (false === password_verify($_POST['userpassword'],$hash)){
- echo"login fail";
- exit;
- }
- }
- }
- <?php
- class Database{
- protected $pdo;
- public function __construct()
- {
- $this->db_connect();
- }
- private function db_connect()
- {
- $servername = "localhost";
- $username = "abc";
- $password = "abc";
- $dbname = "mydb";
- try
- {
- $this->pdo = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
- $this->pdo->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION);
- $this->pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES,false);
- }catch(PDOException $e)
- {
- die("error connection ".$e->getMessage());
- }
- }
- public function getConnection()
- {
- return $this->pdo;
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement