i have a simple php login script with session but all i get is just a white blank page after running my login,php script. Here is the login,php page

<?php
error_reporting( E_ALL );
ini_set( 'display_errors', 1 );
include('connect.php');
session_start();
if (isset ($_POST['submit'])) {
    $UserName=$_POST['uname'];
    $Password=$_POST['pswd'];
    $result=mysql_query("select * from bizness_profile where bizness_email='$Username' and bizness_pswd='$Password'") or die (mysql_error());

    $count=mysql_num_rows($result);
    $row=mysql_fetch_array($result);

if ($count > 0) {
session_start();
$SESSION_ID['user_id']=$row['user_id'];
header('location:update_profile.php');
}else{
header('location:index1.html');
}
}
?>

Recommended Answers

All 12 Replies

yes it does, its for th submit button. i have even tried using

error_reporting( E_ALL );
ini_set( 'display_errors', 1 );

for error but still all i get is a blank page. i really need help to fix this. i believe the php code is correct, just something else wrong. please i need help, this is a common php session problems but just my first time

Seems you've not pass any form data or $_POST['submit'] was not set. What's your page before reaching to 'login.php' ?

And, why session_start() twice ?

this is the code of form from the page b4 reaching login.php

 <form method="POST" action="login.php">
            <p style="padding:8px 0 0 28px;">
            &nbsp;</p>
            <table border="0" width="100%" bgcolor="#E58E11">
                <tr>
                    <td><font size="2" color="#FFFFFF">Email address</font></td>
                </tr>
                <tr>
                    <td><input type="text" name="uname" size="29"></td>
                </tr>
                <tr>
                    <td><font size="2" color="#FFFFFF">Password</font></td>
                </tr>
                <tr>
                    <td><input type="password" name="pswd" size="29"> </td>
                </tr>
            </table>
            <p style="padding:8px 0 0 28px;">
            <input type="submit" value="Submit" name="B3">
            <input type="reset" value="Reset" name="B4">&nbsp; 
          </p>
            </form>

The submit button is not named submit, it's named B3, therefor that $_POST['submit'] should actually be $_POST['B3']

Change the name of submit button, also describe the session on the top of the code.

I relly appreciate your help guys but afta changing the name of the submit button to "B3". it just takes me back to the "index1.html" file nw

A couple of things with your login script. The variables for username do not match - $UserName stores the post data - $Username is declared in mysql query. This is probably causing the the query fail ($Username is unknown) returning zero rows. Therefore it will return you to index1.html as $count is not greater than zero. Also you have declared session_start() twice which will generate an error. You only need to call session_start() once on the page, before any html output.

thank you guys, it is now working.here is the final code.

<?php
error_reporting( E_ALL );
ini_set( 'display_errors', 1 );
include('connect.php');
session_start();
if (isset ($_POST['B3'])) {
    $Username=$_POST['uname'];
    $Password=$_POST['pswd'];
    $result=mysql_query("select * from bizness_profile where bizness_email='$Username' and bizness_pswd='$Password'") or die (mysql_error());
    $msg='';
    $count=mysql_num_rows($result);
    $row=mysql_fetch_array($result);

if ($count > 0) {
//session_start();
$SESSION_ID['user_id']=$row['user_id'];
header('location:update_account.html');
}else{
$msg = "Wrong Username or Password. Please retry";
header('location:index1.html?msg=$msg');
}
}
?>

But i have another challenge. i need to make the user now logged in see something like "Welcome, Peter" as well as a logout button.Also the

error message

doesnt seem to appear in a wrong login attempt.

To make the error message "appear" you will need to GET the msg variable and echo in index1.html.

To show the user is logged in you will need to check if the session id exists. If true echo user logged in and echo a logout button.

Both of the above are quck and esay fixes to your issue. For a more comprehensive solution I would create some sort of site wide an error processing methodology to handle all errors (which can include successes and warnings).

here is my code to show welcome message at the top of secure page after login.

 <?php
include('connect.php');
session_start();
if($SESSION['bizness_name']) {
?>
Welcome, <?php echo $SESSION['bizness_name']; ?>. Click here to <a href="logout.php" tite="Logout">Logout.
<?php
}
?>

but the "bizness_name" isnt showing. it just skipps it and shows "Welcome, . Click here to Logout. "

pls help somebody

First of all when working with sessions in php, make sure that session_start() is first (not after include('connect.php); line, but before.). And, what is $SESSION[...]? Are you sure is not $_SESSION[...]?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.