i've encountered problem while programming log-in script. take @ code:
<?php if(isset($submit)){ require 'db/connect.php'; $sql = "select id users password='$password' , email='$email'"; $entered_user = mysql_query($sql); $num_rows = mysql_num_rows($entered_user); $errors = array(); if( $num_rows != 1 ) { $errors[] = '-account not exist '; } elseif( $num_rows == 1 ) { session_start(); while($row = mysql_fetch_array($entered_user)){ $_session['id'] = $row['id']; $_session['email'] = $email; $_session['user'] = $row['username']; $_session['pass'] = $password; header('location: profile.php'); exit(); } } } ?> after user has submitted password , email, attempt store following in session variables: id, username, password , email. reason username not being stored , outputted on profile.php, redirected. here profile.php code:
<?php session_start(); ?> <html> <head> <title>profile</title> <link href='css/main.css' rel='stylesheet' /> </head> <body> <div id='container'> <?php require 'include/header.php'; ?> <?= 'njm id # ==>'.$_session['id'].'<br />'.'username ==>'.$_session['user'].'<br/>'.'password ==>'.$_session['pass'] ?> <?php require 'include/footer.php'; ?> </div> </div> </body> </html> if knows how fix issue please help. have learned html, css, js , php 2 months ago beginner :)
i've got few remarks on code fix issues.
sessions should started before of other code executed. prevent strange problems arising.
check if session isn't set.
recommended way versions of php >= 5.4.0
if ( session_status() == php_session_none ) { session_start(); } for versions of php < 5.4.0
if (session_id() == '') { session_start(); } use
mysqli_*orpdoqueries.mysql_*deprecated , unsafe.your query isn't fetchin username
change:
$sql = "select id users password='$password' , email='$email'"; to:
$sql = "select id id, username username users password='".$password."' , email='".$email."'";
Comments
Post a Comment