Jump to content

[SOLVED] $_POST Help


Crew-Portal

Recommended Posts

I Made A Login Script For A Website But i need Help To Make It So The Person Who Is logged In Can View Thier Name On The Side Of The Page And So That When They Post Something There Username Gets Posted As Well!

The Script Is:

 

<?php

$userlog = $_POST["username"];

echo $userlog;

?>

 

But I Cant Seem To Figure Out How To Get The Username To Be Shown Until They Destroy The Session

 

  Any Help Would Be Appreciated!!

Link to comment
Share on other sites

I Dont Really understand My Script For Login Is A Follows Just Please Add The Script Where I Need It!

 

if (session_is_registered("CID")){

$showtable = false;

}

?>

<title><?php $name ?></title>

<link rel="stylesheet" href="style.css" type="text/css" />

<body bgcolor="#64748B">

<center>

<table width="850" border="0" cellspacing="0" cellpadding="0">

<tr bgcolor="#26354A">

<td width="514" nowrap="nowrap"><p align="right" class="logo">VirAir International       <br>

<span class="tagline">Paving The Skies In Flight Simulator                   </span></td>

<td width="50" height="70" nowrap="nowrap" class="logo"><p class="logo">

  </td>

<td width="286"><?php

            if ($showtable){

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

            ?>

  <form action="<?php print "$PHP_SELF"; ?>" method="POST">

    <table border="0" cellpadding="2" cellspacing="2">

          <tr>

            <td class="flights">Username: </td>

            <td><input type="text" name="username" value="" />

               </td>

          </tr>

          <tr>

            <td class="flights">Password: </td>

            <td><input type="password" name="password" value="" />

               </td>

          </tr>

          <tr>

            <td class="flights"> </td>

            <td><input type="submit" name="userlogin" value="Login" /></td>

          </tr>

        </table>

        <?php

}

else{

?>

        <a href="index.php?page=modiinfo">Modify Information</a> | <a href="index.php?page=modipass">Modify Password</a> | <a href="index.php?page=logout">Logout</a>

        <?php

}

?>

      </form>

      </td>

</tr>

</table>

<table width="854" border="0">

      <td class="NavTop">

 

 

<?php

    if ($showtable){

//Non Logged In Members Below

    ?>

<a href="index.php?page=signup">Sign Up!</a>

<?php

}

else{

//Logged Members Below!

?>

<a href="index.php?page=postflight">Post Flight</a>

<?php

}

?> </td>

Link to comment
Share on other sites

In order for you to use session variables you need to call the session_start(); function first. Also you can eliminate a step by checking if your session variable is initialized.

 

<?php session_start(); ?>
<title><?php echo "$name"; ?></title>
<link rel="stylesheet" href="style.css" type="text/css" />
<body bgcolor="#64748B">
<center>
<table width="850" border="0" cellspacing="0" cellpadding="0">
   <tr bgcolor="#26354A">
   <td width="514" nowrap="nowrap"><p align="right" class="logo">VirAir International       

   <span class="tagline">Paving The Skies In Flight Simulator                   </span></td>
   <td width="50" height="70" nowrap="nowrap" class="logo"><p class="logo">
     </td>
   <td width="286"><?php
            if (!$_SESSION['username']){
        
         $_SESSION['username'] = $row['username'];
            ?>
     <form action="<?php print "$PHP_SELF"; ?>" method="POST">
       <table border="0" cellpadding="2" cellspacing="2">
          <tr>
            <td class="flights">Username: </td>
            <td><input type="text" name="username" value="" />
               </td>
          </tr>
          <tr>
            <td class="flights">Password: </td>
            <td><input type="password" name="password" value="" />
               </td>
          </tr>
          <tr>
            <td class="flights"> </td>
            <td><input type="submit" name="userlogin" value="Login" /></td>
          </tr>
        </table>
        <?php
   }
   else{
   ?>
        <a href="index.php?page=modiinfo">Modify Information[/url] | <a href="index.php?page=modipass">Modify Password[/url] | <a href="index.php?page=logout">Logout[/url]
        <?php
   }
   ?>
      </form>
      </td>
   </tr>
</table>
<table width="854" border="0">
      <td class="NavTop">
   
   
   <?php
    if (!$_SESSION['username']){
   //Non Logged In Members Below
    ?>
   <a href="index.php?page=signup">Sign Up![/url]
   <?php
   }
   else{
   //Logged Members Below!
   ?>
   <a href="index.php?page=postflight">Post Flight[/url]
   <?php
   }
   ?>   </td>

 

you may need to modify it a little but you should get the picture.

Link to comment
Share on other sites

I Am Sorry I Am Porbably Making All Of You Guys So Mad! I Dint post the entire script last time so unfourtunitly here is my index.php script:

 

<?php
session_start();
require("require/CustomSql.inc.php");
require("require/setting.php");			
require("require/common.php");	
require("require/main_common.php");
$db = new CustomSQL($DBName);
$showtable = true;
$errortag = false;
if (!empty($userlogin)) {

if (empty($username)){
$errortag = true;
$errormsg = $error_usernameempty;
}

if (empty($password)){
$errortag = true;
$errormsg = $error_passwordempty;
}

$customerid = $db->logincheck($username,$password);
if ($customerid==0) {
$errortag = true;
$errormsg = $error_wrongpassword;
}

if (!$errortag){
session_register("CID");
$_SESSION["CID"] = $customerid;
$CID = $customerid;
$showtable = false;
}

}

if (session_is_registered("CID")){
$showtable = false;
}
if (!empty($adduser)) {

if (empty($username)){
$errortag = true;
$errormsg = $error_usernameempty;
}

if (empty($password)){
$errortag = true;
$errormsg = $error_passwordempty;
}

if (empty($email)){
$errortag = true;
$errormsg = $error_emailempty;
}

$usernamecheckresult = $db->checkusername($username);
if (!empty($usernamecheckresult)) {
$errortag = true;
$errormsg = $error_userexist;
}

if ($password!=$passretype){
$errortag = true;
$errormsg = $error_passretypewrong;
}

if ($email!=$emailretype){
$errortag = true;
$errormsg = $error_emailretypewrong;
}

if (!ereg("@", $email)) {
$errortag = true;
$errormsg = $error_email;
}

if (!$errortag){
$customerid = $db->adduser($username,$password,$email,$homepage,$icq,$aol,$yahoo,$msn,$location,$occupation,$interests,$biography);
$showtable = false;
}

}

if (session_is_registered("CID")){
$showtable = false;
}
?>
<title>Home Page</title>
<link rel="stylesheet" href="style.css" type="text/css" />
<body bgcolor="#64748B">
<center>
<table width="850" border="0" cellspacing="0" cellpadding="0">
<tr bgcolor="#26354A">
<td width="514" nowrap="nowrap"><p align="right" class="logo">VirAir International       <br>
<span class="tagline">Paving The Skies In Flight Simulator                   </span></td>
<td width="50" height="70" nowrap="nowrap" class="logo"><p class="logo">
  </td>
<td width="286"><?php
            if ($showtable){
            ?>
  <form action="<?php print "$PHP_SELF"; ?>" method="POST">
    <table border="0" cellpadding="2" cellspacing="2">
          <tr>
            <td class="flights">Username: </td>
            <td><input type="text" name="username" value="" />
               </td>
          </tr>
          <tr>
            <td class="flights">Password: </td>
            <td><input type="password" name="password" value="" />
               </td>
          </tr>
          <tr>
            <td class="flights"> </td>
            <td><input type="submit" name="userlogin" value="Login" /></td>
          </tr>
        </table>
        <?php
}
else{
?>
        <a href="index.php?page=modiinfo">Modify Information</a> | <a href="index.php?page=modipass">Modify Password</a> | <a href="index.php?page=logout">Logout</a>
        <?php
}
?>
      </form>
      </td>
</tr>
</table>
<table width="854" border="0">
      <td class="NavTop">


<?php
    if ($showtable){
//Non Logged In Members Below
    ?>
<a href="index.php?page=signup">Sign Up!</a>
<?php
}
else{
//Logged Members Below!
?>
<a href="index.php?page=postflight">Post Flight</a>
<?php
}
?>	</td>
  </tr>
</table>
<table width="850" border="0" cellspacing="0" cellpadding="0">
<tr bgcolor="#FF6600">
<td colspan="6"></td>
</tr>

<tr bgcolor="#D3DCE6">
<td colspan="6"></td>
</tr>

<tr bgcolor="#D3DCE6">
<td colspan="6"></td>
</tr>

<tr bgcolor="#FF6600">
<td colspan="6"></td>
</tr>

<tr bgcolor="#D3DCE6">
<td colspan="2" valign="top" bgcolor="#26354A">
<br>     <a href="index.php?page=flights">View Flights</a><br>
        <?php
for ($i=0;$i<count($dbFieldNames);$i++) 
{
	$TableTitle .= $TDTitStyle.
	' <a href="index.php?page=flights&action=va&s='.$dbFieldNames[$i].'&d='.$sortOptions[$dbFieldNames[$i]].'&p='.$p.'" 
	style="text-decoration:none;color:white">'.$columnNames[$i].'</a></td>'.chr(13);
}
$TDListOdd	='<td nowrap class="flights">';	// define here background and font colors of 
$TRList		='<tr>';
$ListStop	='</table>';
if(!isset($listflight))
{

$query = "select count(*) from flights ".$condition;
$result=mysql_query($query);
if(!$result){echo "SQL Error - ".mysql_error()."<br>".$query;return;}
$NrfFlights=mysql_result($result,0);
# total flight time / block time
$query = "SELECT sec_to_time(sum(time_to_sec(TotalBlockTime))) FROM flights ".$condition;
$result=mysql_query($query);
$TFT = number_format(mysql_result($result,0));
# total passengers
$query = "SELECT sum(NbrPassengers) FROM flights ".$condition;
$result=mysql_query($query);
$TPC = number_format(mysql_result($result,0));
# total cargo weight
$query = "SELECT sum(CargoWeight) FROM flights ".$condition;
$result=mysql_query($query);
$TCKG = number_format(mysql_result($result,0));


echo '<br><table width="1" cellspacing="1" cellpadding="2" align="center" style="font: normal 11px/14px Arial,sans-serif;padding:7px 7px 7px 7px">'.$TDListOdd.
	 "<div align=\"right\">Total flights".$startMsg.": $NrfFlights<br>
	 Total flight time: $TFT h<br>
	 Total passengers carried: $TPC<br>
	 Total Cargo carried: $TCKG Kg</div>".
	 $ListStop;
echo "<br>";
}
?>
        
      </td>
<td width="5"></td>
<td width="603" valign="top">
<font color="#FF0000">
 <?php
 print "<center>";
echo "<table width=450 >";
echo " <tr>";
echo " <td class=error>";
 print "$errormsg";
echo " </td>";
echo " </tr>";
echo "</table>";
print "</center>";
 ?>
 </font>
 <?php
if ($page == NULL){
include 'pages/home.php';
}
elseif (file_exists('pages/' . $page . '.php')) {
include 'pages/' . $page . '.php';
}
elseif ($page == logout){
session_destroy();
}
elseif ($page == notloggedin){
echo 'You Are Not logged in! Too Bad';
}
else include 'pages/error.php';
	?>
<td width="10" valign="top"> </td>
</tr>

<tr bgcolor="#D3DCE6">
<td colspan="6"></td>
</tr>
</table>
<table width="854" border="0">
  <tr bgcolor="#FFCC00">
    <td><div align="center">Copywrite VirAir International. All Rights Reserved. | Link | Link | Link | Link | Link | </div></td>
  </tr>
</table>
</body>
</html>

Link to comment
Share on other sites

I Am Try to get the script to display the username that the member is logged into using $_POST['username']; But I cant seem to figure out how to get that information to stay ustil the user logs out. Right now its only displaying once and thats when they log in. But when the navigate to another page thier name dissapears! It doesnt seem like much but I need gthat script so users can post a flight (I mean using the game flight simulator) and so that it posts thier username along with the post! I have tried my supervariable $username. which should be used when they log in but for some reason it just shows up blank like a ( ) the only script I see that can mildly help is the $_post script but it doesnt stay on the screen! So I just need help on how to make that variable ($_POST) stay until the session is destroyed!

 

my link to webserver is at http://24.76.180.18

Link to comment
Share on other sites

Ok I looked at your site. You need to do is create a session variable with the value of the user logged in. then you can take the session variable holding the username from page to page.

 

<?php
$query=mysql_query("SELECT * FROM users WHERE username='$_POST[username]' AND password='$_POST[password]' ") or die();

$sql=mysql_fetch_array($query);

session_start();

$_SESSION['username']=$sql[username];

echo "you are logged in as: $_SESSION['username']";
?>

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.