Thursday, 15 April 2010

html - PHP not displaying errors? -



html - PHP not displaying errors? -

this question has reply here:

how php errors display? 12 answers

im trying create login scheme errors dont seem display well. advice please? code connects db because there no error displayed when initialize page when click login button, nil happens no errors @ or success message. maybe everyon got confused im trying display errors in if($count == 1){ echo "logged in"; }else{ echo "nooo";}

<?php session_start(); class database { private $host = "127.0.0.1"; private $db_name = "test"; private $db_user = "root"; private $db_pass = ""; private $socket_type = "mysql"; private $instance = null; public function __constructor() { if($this->instance == null){ seek { $db = new pdo( '' . $this->socket_type . ':host' . $this->host . ';db_name='.$this->db_name.'', $this->db_user, $this->db_pass ); $this->instance = $db; } catch(pdoexception $e){ die($e->getmessage()); } } } public function query($sql){ $query = $this->instance->prepare($sql); $query->execute(); homecoming $query; } } class loginsystem { public function login($email, $password){ if(!empty($email) && !empty($password)){ $db = new database; $query = $db->query("select * users email='".$email."' , password='".$password."' "); $count = $query->rowcount(); if($count == 1){ echo "logged in"; }else{ echo "nooo"; } }else{ die("data not recieved"); } } public function encryptpass($password){ if(!empty($password)){ homecoming md5($password); } } public function clean($data){ if(!empty($data)){ $data = trim(strip_tags(stripslashes(mysql_real_escape_string($data)))); homecoming $data; } } } //instatiate classes $db = new database; $loginsystem = new loginsystem; //token $token = crypt("henri-cuni-boss"); $_session['token'] = $token; $main_token = crypt($_session['token']); //check login if(isset($_post['email']) && isset($_post['password'])){ if(isset($_post['token']) == $main_token){ $email = $loginsystem->clean($_post['email']); $password = $loginsystem->clean($_post['password']); if($email != "" && $password != ""){ $md5_pass = $loginsystem->encryptpass($password); $loginsystem->login($email, $md5_pass); } }else { die("invalid token"); } } ?>

this html form ->

<form action="#" method="post"> <input type='hidden' name='token' id='token' value='<?php echo $main_token;?>' /> <input type="email" name="username" id="username" placeholder="vendoseni e-mailin"/> <br/> <input type="password" name="password" id="pass" placeholder="vendoseni passwordin"/> <br/> <input type="submit" value="kycuni" id="login_btn"/> </form>

you have

$email = $loginsystem->clean($_post['email']);

and

<input type="email" name="username" id="username" placeholder="vendoseni e-mailin"/>

the $_post variable must match name attribute of input tag, not type atttribute.

also, i'm not sure validation code good. don't think passwords containing "special" characters <, \, ' or " work.

php html oop pdo

No comments:

Post a Comment