php - login form using session and pdo -


I have started to change my old SQL code to PW, but I have difficulties doing this, I can convert Tried to do my login script in Pda form, this is the conversion

   FetchColumn (); If ($ num> 0) {header ("location: dashboard.php"); } Other {header ("location: login.php"); }} Hold (exception $ E) {echo 'exception:', $ e- & gt; GetMessage (), "\ n"; }}? & Gt;  

The page is not being redirected to any page, instead it is being redirected to an empty page

Your query is not ready because you have 2 WHERE in 2 sql queries. WHERE WHERE email =: email and password =: password

SELECT *

You should set up a connection to remove errors:

  $ conn- & gt; Set attribute (PDO :: ATTR_ERRMODE, PDO :: ERRMODE_EXCEPTION);  

Check all prices not just submit

  if (isset ($ _ POST ['submit'], $ _POST ['email'], $ _POST ['password']))  

Full code:

  & lt ;? Php session_start (); // Start session if set ($ iss_et), $ _POST ['email'], $ _POST ['password'])) {try $ $ email and $ password $ email = $ _POST [ 'E-mail']; $ Password = $ _POST ['password']; // Server $ dbhost = "Connection" with qwe.com; $ Dbname = "qwe"; $ Dbuser = "qwe"; $ Dbpass = "qwe"; $ Conn = new PDO ("mysql: host = $ dbhost; dbname = $ dbname", $ dbuser, $ dbpass); $ Conn- & gt; Set attribute (PDO :: atTRRMODE, PDO :: ERRMODE_EXCEPTION); $ Sql ​​= "SELECT * FROM Register WHERE 'email` =: Email & Password =": Password "; $ Stmt = $ conn- & gt; Ready ($ sql); $ Stmt- & gt; Execution (array (': email' = & gt; $ _POST ['email'], ': password' = & gt; $ _POST ['password'])); $ Num = $ stmt-> ROWCOUNT (); If ($ num> 0) {header ("location: dashboard.php"); } Other {header ("location: login.php"); }} Hold (exception $ E) {echo 'exception:', $ e- & gt; GetMessage (), "\ n"; }}? & Gt;  

Comments