hey guys..i wold like to ask something about my checkLogin.php

i already created a form using index.php, then i want to validate the form using checkLogin.php.
but after i fill up my form, nothing was display..

here aremy codes

<?
session_start();
include("inc/dbconn.inc");

if(isset($_REQUEST['btn_login']))
{
    $conn = mysql_connect($hostname, $username, $password);
    mysql_select_db($dbname, $conn);

    //create short version of variables['name textfield kat login form']
    $name = $_POST['userName'];
    $password = $_POST['password'];

    //retrieve value from login form
    $sql = "SELECT * FROM u_user WHERE userName = '($name)' and password = '($password)'";

    $result = mysql_query($sql,$conn) or die ("Could not execute sql");
    $num_row = mysql_num_rows($result);

    if($num_row == 1)
    {

        session_register("userName");
        session_register("password");

        while($row = mysql_fetch_assoc($result)) {

            #Load different page based on the access level
            if ($row['tahap']=="1")
            {
                header("menu_admin.php");
            }
        }
} else
    {
        //validation    
        ?>
        <h3 style="background:#DEF7FE; font-family:'Times New Roman', Times, serif; 
        font-size:15px; border:1px solid #CCC; color:#OOO; border-radius:10px 10px 10px 10px;
        text-align:center; margin-top:250px; width:500px; padding:8px; 
        margin-left:400px">Your Id or password is incorrect <br />Please <a href="indexBaru.php">log In </a> back</h3>
<?   }

    mysql_close($conn);
}

?>
Member Avatar for LastMitch

@sagisgirl

hey guys..i wold like to ask something about my checkLogin.php

What error messages you got when you ran your code?

This function: session_register(); doesn't work correctly.

Read this:

http://php.net/manual/en/function.session-register.php

Try to used $_SESSION instead.

So on line 23 & 24:

session_register("userName");
session_register("password");

From this

session_register("userName");
session_register("password");

To this:

$_SESSION["userName"] = $name
$_SESSION["password"] = $password

On line 18 add this or die(mysql_error());:

  $num_row = mysql_num_rows($result) or die(mysql_error());

What error did you get or any?

On your query which is on line 15:

$sql = "SELECT * FROM u_user WHERE userName = '($name)' and password = '($password)'";

I change it a little from this:

$sql = "SELECT * FROM u_user WHERE userName = '($name)' and password = '($password)'";

To this:

$sql = "SELECT * FROM u_user WHERE userName='$name' AND password ='$password'";

Run your code again and tell me what you got so far?

Thanks LastMitch, it didn't show any error..it just blank.
i already changed the code.
it still blank.
is there anything wrong with line 31?

Member Avatar for LastMitch

is there anything wrong with line 31?

I don't know maybe you can tell me because what is in $row['tahap']?

I have got the same question and now I solve it, Thank you.

tahap actually means level..it does not contain any value.
actually i wanna do like, admin and user will access different page..

Andrew, dont you wanna shae here.?

Ln 29, take the double quotes off so:-

if ($row['tahap']==1)

Ln 31 single quotes only.

Member Avatar for LastMitch

@sagisgirl

actually i wanna do like, admin and user will access different page..

I'm not sure what you are asking? You mention you have issue login in so there was some minor changes.

The code you provided above is a simple code to vertify the username and password from the db so the person can access all the pages from the admin section.

What TonyG mention, try changes those minor issue too. Then run the code.

So far base on the code you can just used session to access each page.

ok..im sorry for confusing you guys..i already figure it out to solve this prob..
thanks for your helping.. :D

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.