php - Issue while trying to read Table - MySQL -
i believe basic problem starting coding @ php can't alone:
i've been 2 days trying solve strange problem. using xampp database , tables objective of creating login , register system.
this user table:
create table `playware`.`users` ( `user_id` int( 5 ) not null auto_increment primary key , `name` varchar( 25 ) not null , `surname` varchar( 25 ) not null , `email` varchar( 35 ) not null , `telephone` varchar( 9 ) not null , `password` varchar( 50 ) not null , unique (`email`) ) engine = myisam ;
the register .php file working (it's adding user table correctly) when try make login can't.
so i've made on login.php file test if gets row:
<?php include_once 'connect.php'; session_start(); if(isset($_session['user'])!="") { header("location: index_home.php"); } $email = $_post["email"]; $upass = $_post["password"]; $sql="select email users"; $res=$conn->query($sql); if($res->num_rows>0) { while($row=$res->fetch_assoc()); { if($row["email"]==$email) { echo"writting email: ".$row["email"]." - done writting."; } } } ?>
all time try results on white screen, nothing more, when it's supposed appear user email. knows how fix this?
================================update================================== error was:
while($row=$res->fetch_assoc()); { //stuff here ... }
it can't take ";" there because cancels outputting. fix is:
while($row=$res->fetch_assoc()) (...)
as expected, basic error ... thank people supported me.
you have error here:
if(isset($_session['user'])!="")
you cannot check if variable set , not equal blank in way. instead should this:
if(isset($_session['user']) && $_session['user']!="")
you have error here, stops script outputting anything:
while($row=$res->fetch_assoc()); ---------remove -----------^
since valid syntax may not have seen in error reporting.
you should use php's built-in functions handle password security. if you're using php version less 5.5 can use password_hash()
compatibility pack.
in addition make sure you're using prepared statements pdo and/or mysqli , consider using pdo, it's pretty easy.
Comments
Post a Comment