Jump to content

Capturing username.


jurass1c

Recommended Posts

      <form name="form" id="form" class="form" action="insert.php" method="post">

        <tr>

          <td width="89" height="27" align="left" valign="middle"> Album Cover: </td>

          <td width="308" align="left" valign="middle">

            <input name="cover" type="text" size="40" />

            *</td>

          <td width="253" rowspan="9" align="center" valign="middle"> </td>

            </tr>

        <tr>

          <td height="28" align="left" valign="middle"> Album:</td>

          <td align="left" valign="middle"><input name="album" type="text" size="40" />

            *</td>

            </tr>

        <tr>

          <td height="29" align="left" valign="middle"> Artist: </td>

          <td align="left" valign="middle"><input name="artist" type="text"  size="40" />

            *</td>

            </tr>

        <tr>

          <td height="29" align="left" valign="middle"> Album Year: </td>

          <td align="left" valign="middle"><select name="album_year">

            <option value="">Unkown</option>

            <option value="2010">2010</option> 

            <option value="2009">2009</option> 

            <option value="2008">2008</option> 

            <option value="2007">2007</option> 

            <option value="2006">2006</option> 

            <option value="2005">2005</option> 

            <option value="2004">2004</option> 

            <option value="2003">2003</option> 

            <option value="2002">2002</option> 

            <option value="2001">2001</option> 

            <option value="2000">2000</option> 

            <option value="1999">1999</option> 

            <option value="1998">1998</option> 

            <option value="1997">1997</option> 

            <option value="1996">1996</option> 

            <option value="1995">1995</option> 

            <option value="1994">1994</option> 

            <option value="1993">1993</option> 

            <option value="1992">1992</option> 

            <option value="1991">1991</option> 

            <option value="1990">1990</option> 

      </select> *</td>

            </tr>

        <tr>

          <div align="right"><input type="submit" class="btn" value="Share" /></div>

            <br />

            <br />

            <br /></td>

            </tr>

      </form>

sorry guys lol.

 

 <fieldset id="signin_menu">
    <form method="post" id="signin" action="indxlog.php" name="login">
      <label for="username">Username or email</label>
      <input name="usr_email" id="name" class="required"  value="" title="username" tabindex="4" type="text">
      </p>
      <p>
        <label for="password">Password</label>
        <input id="password "name="pwd" class="required password" value="" title="password" tabindex="5" type="password">
      </p>
      <p class="remember">
        <input id="signin_submit" value="Sign in" tabindex="6" type="submit">
        <input id="remember" name="remember" value="1" tabindex="7" type="checkbox">
        <label for="remember">Remember me</label>
      </p>
      <p class="forgot"> <a href="#" id="resend_password_link">Forgot your password</a> </p>
      <p class="forgot-username"> <A id=forgot_username_link 
title="Activation code will be required" 
href="#">Activate Account</A> </p>
    </form>
  </fieldset>

No luck there here is what i use in the usr_email variable

 

{
$user_email = mysql_real_escape_string($_POST['usr_email']);
$md5pass = md5(mysql_real_escape_string($_POST['pwd']));


if (strpos($user_email,'@') === false) {
    $user_cond = "user_name='$user_email'";
} else {
      $user_cond = "user_email='$user_email'";
    
}

 

so the user can either log in by email or username. This is the session code

 

     // this sets session and logs user in  
   session_start(); 
   
   // this sets variables in the session 
	$_SESSION['user_id']= $id;  
	$_SESSION['user_name']= $_POST['user_name'];



	//set a cookie witout expiry until 60 days
   if(isset($_POST['remember'])){
			  setcookie("user_id", $_SESSION['user_id'], time()+60*60*24*60, "/"); //60 sec * 60 min * 24 hours * 60 days
			  setcookie("user_name", $_SESSION['user_name'], time()+60*60*24*60, "/"); //60 sec * 60 min * 24 hours * 60 days
			   }


	header("Location: account.php");
	}
	else
	{
	$msg = urlencode("Invalid Login. Please try again with correct user email and password. ");
	header("Location:login.php?msg=$msg");
	}

 

I use this code to protect pages and start sessions.

 

******************** PAGE PROTECT CODE  ***************/

function page_protect() {
session_start();

//check for cookies

if(isset($_COOKIE['user_id']) && isset($_COOKIE['user_name'])){
      $_SESSION['user_id'] = $_COOKIE['user_id'];
      $_SESSION['user_name'] = $_COOKIE['user_name'];
   }

if (!isset($_SESSION['user_id']))
{
header("Location: login.php");
}

/******************************************************/

}

 

So i use this variable $_SESSION[user_name] in the file that insert's content and i want to capture and post the username  in this below file

 

<?php
include 'db.php';
page_protect();


$user_ip = $_SERVER['REMOTE_ADDR'];

$sql="INSERT INTO example (cover, album, artist, date, users_ip, user_name,  album_year)

VALUES
('$_POST[cover]','$_POST[album]','$_POST[artist]', now(), '$user_ip',  '$_SESSION[user_name]',  '$_POST[album_year]')";

if (!mysql_query($sql))
  {
  die('Error: ' . mysql_error());
  }
  
header("Location: share.php");  
  exit();

?> 

 

where am i going wrong ?

You use $_POST to get the form values from the previous page.  I noticed that on your login form, the action is set to indxlog.php.  However, you're using check.php to look for the $_POST form values from the login page.

 

The indxlog.php will need to get the $_POST values.  If you do a var_dump($_POST) in indxlog.php, you should see the form values there.  The indxlog.php page should be the one to check if the username is valid and then set it to the $_SESSION if valid.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.