Jump to content

need help in my login form


pixeltrace

Recommended Posts

guys,

 

i also need help in my login form,

i have 3 page

1. index.php

2. checkuser.php

3. main.php

 

so when i login to index.php - checkuser.php will validate the user

once done it will bring me to main.php

 

my problem is, in main.php it not getting the data from checkuser.php

let say i have username: peterparker

 

when i get to main.php the field where peterparker's first name and last name should be shown is not appearing

but just the variable.

 

this is the code for my index.php

<?php
include 'db_connect.php';
?>
<form action="checkUser.php" method="post" name="frmLogin">
          <table width="260" border="1" align="center" cellpadding="0" cellspacing="0" bordercolor="#2A4DAB">
            <tr>
              <td width="276"><table width="260" border="0" align="center" cellpadding="4" cellspacing="0">
                  <tr>
                    <td height="2" colspan="3" valign="top"><img src="images/spacer.gif" width="10" height="2"></td>
                    </tr>
                  <tr>
                    <td colspan="3" bgcolor="#5F9DE3" class="text2">STAFF LOGIN </td>
                  </tr>
                  <tr>
                    <td colspan="3" valign="top"><img src="images/spacer.gif" width="10" height="2"></td>
                  </tr>
                  <tr>
                    <td width="30%" align="right"><span class="text1">User</span></td>
                    <td colspan="2"align="left"><input name="username" type="username" id="username" /></td>
                  </tr>
                  <tr>
                    <td align="right"><span class="text1">Password</span></td>
                    <td colspan="2" align="left">
                        <input name="password" type="password" id="password" />                    </td>
                  </tr>
                  <tr>
                    <td> </td>
                    <td width="21%">
                    <input type="submit" name="Submit" value="Login" class="mybutton" />                    </td>
                    <td width="49%"> <a href="forgotpass.php" class="link1">forgot your password?</a></td>
                  </tr>
                  <tr>
                    <td> </td>
                    <td colspan="2"> </td>
                  </tr>
              </table></td>
            </tr>
          </table>
        </form>

 

this is the code for my checkuser.php

<?
session_start();

$username = $_POST['username'];
$password = md5($_POST['password']);

if(empty($username) || empty($password)){
echo '<script language=javascript> alert("Please enter ALL of the information!");</script>';
echo '<script language=javascript> top.location = "index.php";</script>';
exit();
}

include 'db_connect.php';

$result = mysql_query("SELECT userid, user_level FROM admin_user WHERE username = '{$username}' AND password = '{$password}'");

$numb_rows = mysql_num_rows($result);
if($numb_rows == 0)
{
   //NOT A VALID LOGIN/PASSWORD
   echo '<script language=javascript> alert("You could not be logged in! Either the username and password do not match! Please try again!");</script>';
   echo '<script language=javascript> top.location = "index.php";</script>';

  die();
}

$row = mysql_fetch_assoc($result);

$_SESSION['userid'] = $row['userid'];
$_SESSION['username'] = $username;
$_SESSION['user_level'] = $row['user_level'];

mysql_query("UPDATE users SET last_login=now() WHERE userid=" . $row['userid'] . "");

if($row['user_level'] == 'administrator')
{
    header("Location: main.php");
}
else if($row['user_level'] == 'staff')
{
    header("Location: main2.php");
}

?>

 

and this is the code for my main.php

<?
session_start();

if (session_is_registered("username")){
if($_SESSION['user_level'] == 'administrator'){

$username = $_GET['username'];

include 'db_connect.php';

$uSql = "SELECT first_name, last_name, job_title FROM admin_user WHERE username= '$username'";
$uResult = mysql_query($uSql, $connection);
if(!$uResult){
    echo 'no data found';
}
?>

Welcome <? echo '$first_name $last_name' ?> :: <? echo '$job_title' ?>

 

 

what's wrong in my codes?

need help please!

 

Thanks in advance!

Link to comment
Share on other sites

umm im not sure but this might be it in your checkuser.php your using

$username = $_POST['username'];

$_SESSION['username'] = $username;

and in you main.php

your using

$username = $_GET['username'];

I think in you main.php it should be

$username = $_SESSION['username'];

 

because your not sending any get variables your just redirecting it to

header("main.php");

if it was

header("main.php?username=$username");

than i think that will work too

Link to comment
Share on other sites

hi,

 

i changed the codes in main.php already but its still not working

this is the current codes in my main.php

<?
session_start();

if (session_is_registered("username")){
if($_SESSION['user_level'] == 'administrator'){

$username = $_SESSION['username'];

include 'db_connect.php';

$uSql = "SELECT first_name, last_name, job_title FROM admin_user WHERE username= '$username'";
$uResult = mysql_query($uSql, $connection);
if(!$uResult){
    echo 'no data found';
}
?>

Link to comment
Share on other sites

hi,

 

i changed the codes in main.php already but its still not working

this is the current codes in my main.php

<?
session_start();

if (session_is_registered("username")){
if($_SESSION['user_level'] == 'administrator'){

$username = $_SESSION['username'];

include 'db_connect.php';

$uSql = "SELECT first_name, last_name, job_title FROM admin_user WHERE username= '$username'";
$uResult = mysql_query($uSql, $connection);
if(!$uResult){
    echo 'no data found';
}
?>

 

your missing one or two } at the end it should be

 

<?
session_start();

if (session_is_registered("username")){
if($_SESSION['user_level'] == 'administrator'){

$username = $_SESSION['username'];

include 'db_connect.php';

$uSql = "SELECT first_name, last_name, job_title FROM admin_user WHERE username= '$username'";
$uResult = mysql_query($uSql, $connection);
if(!$uResult){
    echo 'no data found';
} 
}
}
?>

if that doesnt work try taking one off thats the only problem i see

Link to comment
Share on other sites

its still not working. :(

this is the error i am getting

Parse error: parse error, unexpected '}' in c:\hosting\webhost4life\member\diorgrace\admean\main.php on line 77

 

this is the current entire codes in my main.php page

<?
session_start();

if (session_is_registered("username")){
if($_SESSION['user_level'] == 'administrator'){

$username = $_SESSION['username'];

include 'db_connect.php';

$uSql = "SELECT first_name, last_name, job_title FROM admin_user WHERE username= '$username'";
$uResult = mysql_query($uSql, $connection);
if(!$uResult){
    echo 'no data found';
} 
}
}
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>:: JobHiRings :: Administration Page</title>
<style type="text/css">
<!--
body {
margin-left: 0px;
margin-top: 10px;
margin-right: 0px;
margin-bottom: 0px;
}
-->
</style>
<link href="../CSS.css" rel="stylesheet" type="text/css">
<link href="css.css" rel="stylesheet" type="text/css">
</head>

<body>
<table width="778" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td colspan="3"><img src="images/header.gif" width="778" height="148"></td>
  </tr>
  <tr>
    <td width="16" rowspan="2" align="left" valign="top" background="images/left.gif"><img src="images/left.gif" width="16" height="14"></td>
    <td width="745" valign="top"><table width="746" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td width="746" colspan="2"> </td>
      </tr>
      <tr>
        <td colspan="2">Welcome <? echo '$first_name $last_name' ?> :: <? echo '$job_title' ?></td>
      </tr>
      <tr>
        <td> </td>
        <td> </td>
      </tr>
      <tr>
        <td colspan="2"> </td>
      </tr>
    </table></td>
    <td width="16" rowspan="2" align="right" valign="top" background="images/right.gif"><img src="images/spacer.gif" width="1" height="1"><img src="images/right.gif" width="16" height="14"></td>
  </tr>
  <tr>
    <td valign="top"><img src="images/spacer.gif" width="746" height="10"></td>
  </tr>
  <tr>
    <td colspan="3" background="images/footer.gif"><table width="583" border="0" align="center" cellpadding="0" cellspacing="0">
      <tr>
        <td width="12" rowspan="2"><img src="images/spacer.gif" width="12" height="43"></td>
        <td width="560" height="10" valign="top"><img src="images/spacer.gif" width="12" height="10"></td>
        <td width="12" rowspan="2"><img src="images/spacer.gif" width="12" height="43"></td>
      </tr>
      <tr>
        <td align="center" valign="top" class="footer">Copyright © 2007 www.jobhirings.com. All Rights Reserved</td>
      </tr>
    </table></td>
  </tr>
</table>
<?
}else{
echo "<font face=\"Arial\">You are not authorized to access this page ... Please <a href='index.php'>Login</a></font>";
}
}else{
   echo '<script language=javascript>top.location = "index.php";</script>';
}

?>
</body>

</html>

Link to comment
Share on other sites

<?
session_start();

if (session_is_registered("username")){
if($_SESSION['user_level'] == 'administrator'){

$username = $_SESSION['username'];

include 'db_connect.php';

$uSql = "SELECT first_name, last_name, job_title FROM admin_user WHERE username= '$username'";
$uResult = mysql_query($uSql, $connection);
if(!$uResult){
    echo 'no data found';
} 
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>:: JobHiRings :: Administration Page</title>
<style type="text/css">
<!--
body {
margin-left: 0px;
margin-top: 10px;
margin-right: 0px;
margin-bottom: 0px;
}
-->
</style>
<link href="../CSS.css" rel="stylesheet" type="text/css">
<link href="css.css" rel="stylesheet" type="text/css">
</head>

<body>
<table width="778" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td colspan="3"><img src="images/header.gif" width="778" height="148"></td>
  </tr>
  <tr>
    <td width="16" rowspan="2" align="left" valign="top" background="images/left.gif"><img src="images/left.gif" width="16" height="14"></td>
    <td width="745" valign="top"><table width="746" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td width="746" colspan="2"> </td>
      </tr>
      <tr>
        <td colspan="2">Welcome<? echo " ".$first_name." ".$last_name." "; ?>:: <? echo $job_title; ?></td>
      </tr>
      <tr>
        <td> </td>
        <td> </td>
      </tr>
      <tr>
        <td colspan="2"> </td>
      </tr>
    </table></td>
    <td width="16" rowspan="2" align="right" valign="top" background="images/right.gif"><img src="images/spacer.gif" width="1" height="1"><img src="images/right.gif" width="16" height="14"></td>
  </tr>
  <tr>
    <td valign="top"><img src="images/spacer.gif" width="746" height="10"></td>
  </tr>
  <tr>
    <td colspan="3" background="images/footer.gif"><table width="583" border="0" align="center" cellpadding="0" cellspacing="0">
      <tr>
        <td width="12" rowspan="2"><img src="images/spacer.gif" width="12" height="43"></td>
        <td width="560" height="10" valign="top"><img src="images/spacer.gif" width="12" height="10"></td>
        <td width="12" rowspan="2"><img src="images/spacer.gif" width="12" height="43"></td>
      </tr>
      <tr>
        <td align="center" valign="top" class="footer">Copyright © 2007 www.jobhirings.com. All Rights Reserved</td>
      </tr>
    </table></td>
  </tr>
</table>
<?
}else{
echo "<font face=\"Arial\">You are not authorized to access this page ... Please <a href='index.php'>Login</a></font>";
}
}else{
   echo '<script language=javascript>top.location = "index.php";</script>';
}

?>
</body>

</html>

the problems definitly in main.php and there i fixed it i think

you were missing ; at the end of echo'' but try copying th code above

Link to comment
Share on other sites

thats weird try checking if the values are even gotten from the database try and echo them right after the query to make sure the login check is working

if thats working try changing

<td colspan="2">Welcome<? echo " ".$first_name." ".$last_name." "; ?>:: <? echo $job_title; ?></td>

to

<td colspan="2">Welcome<? echo " $first_name $last_name "; ?>:: <? echo $job_title; ?></td>

Link to comment
Share on other sites

include 'db_connect.php';
$uSql = "SELECT first_name, last_name, job_title FROM admin_user WHERE username= '$username'";
$uResult = mysql_query($uSql, $connection);

there not showing up because your not assigning the variables

try

$query = mysql_query("SELECT first_name, last_name, job_title FROM admin_user WHERE username= '$username'") or die(mysql_error()); 
$row = mysql_fetch_array( $query );
$first_name = $row["first_name"];
$last_name  = $row["last_name"];
$job_title = $row["job_title"];

 

Link to comment
Share on other sites

If this helps any, basically the period is a separator.

Everything in the quotes of an echo, will be echoed.

if you echo:

echo "$grge rules";

 

then your browser will spell out:

$grge rules

 

but, if you echo:

echo $grge . "rules";

 

then your browser will spell out:

George rules

 

or if you echo:

echo "I think" . $grge . "smells";

 

then your browser will spell out:

I think George smells

 

The dot acts as a separator between variables and exact phrases...

 

If you want to see, try this:

<?php
$grge = George;

echo "$grge rules";
echo "<br />;

echo $grge . "rules";
echo "<br />;

echo "Rules does," . $grge;
echo "<br />;

echo "I think" . $grge . "smells";
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.