PHP Help

Status
Not open for further replies.

NSA

sudo apt-get thefuckout.tar.gz
Dec 9, 2011
715
86
Hello all,

I am trying to echo a username from $_SESSION['username'];
But I keep getting many errors when I try using different methods.

When I use: "$_SESSION['username'] = $username;" I get "Undefined Index: $username"
When I use: "$_SESSION['username'];" and try to call it on another page using "$userName = $_SESSION['username'];" I just get a blank response.

Can someone please help me to use $_SESSION to do this, please?

Thanks,
Western_Corleone
 

Clawed

Whats occuring?
Jun 2, 2012
51
3
PHP:
<?php
 
if( isset( $_SESSION['username'] ) and isset( $_SESSION['password'] ) ) {
 
$username = mysql_real_escape_string( $_SESSION['username'] );
$password = mysql_real_escape_string( $_SESSION['password'] );
 
$query = mysql_query( "SELECT * FROM users WHERE username = '" . $username . "' AND password = '" . $password . "' LIMIT 1" );
 
if( mysql_num_rows( $query ) > 0 ) {
 
$logged = mysql_fetch_assoc( $query );
 
}
 
}
 
echo $logged['username'];
echo $logged['password'];
echo $logged['email'];
 
?>

and all over rows in the table to validate from database.

Edit:

PHP:
<?php echo $logged['password']; ?>
This was an example.
 

NSA

sudo apt-get thefuckout.tar.gz
Dec 9, 2011
715
86
Neither of the solutions worked, which is really bugging me.

Is there something that's maybe disabled?
 

Li1M0ST3Rz

I <3 Bianca
Sep 13, 2010
269
166
No. it happen to me. i'll add get format:
PHP:
<?php
if(isset($_GET['loggin'])
{
  //code here
}
?>
and it never giving me error on SupremeCMS or just create a class/function. either one will work
 

NSA

sudo apt-get thefuckout.tar.gz
Dec 9, 2011
715
86
After using this, it seems I get some weird errors.

1) When I put the wrong username and or password, I get "Wrong username or password"
2) When I put the correct username and or password, I get "Notice: Undefined index: username in F:\xampp-portable\htdocs\login.php on line 14

Notice: Undefined index: password in F:\xampp-portable\htdocs\login.php on line 15
Wrong Username or Password"

You can see the error here:

Pretty weird that it only gives this error when it's correct.
 

DaLightz

See ya'll in the afterlife.
May 19, 2012
1,136
262
What's with the ''. .'' ..?

Post your full code, no one wants to try and make sense of it while looking at it on a youtube clip.
It only requires basic php knowledge to know what that means. Therefore, if you don't know what that means. You really, need to brush up on your php.
 

Ecko

23:37 [autobots] -!- eckostylez [[email protected]]
Nov 25, 2012
1,398
962
It only requires basic php knowledge to know what that means. Therefore, if you don't know what that means. You really, need to brush up on your php.
I know exactly what it means, I'm wondering why you are even using it when it is utterly useless. All you need is.
PHP:
echo $user;

Your method would only be necessary if you were echoing plaintext before the variable.
 

NSA

sudo apt-get thefuckout.tar.gz
Dec 9, 2011
715
86
Here is the "login.php" the login page is too big to paste and I think it's un-needed:
PHP:
<?php
 
$host="localhost";
$username="root";
$password="";
$db_name="site";
$tbl_name="users";
 
 
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
 
 
$myusername = $_POST['username'];
$mypassword = $_POST['password'];
 
 
$myusername = stripslashes($myusername);
$mypassword = stripslashes($mypassword);
$myusername = mysql_real_escape_string($myusername);
$mypassword = mysql_real_escape_string($mypassword);
$sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'";
$result=mysql_query($sql);
 
 
$count=mysql_num_rows($result);
 
 
if($count==1){
session_start();
$_SESSION['myusername'] = $myusername;
header("location:login_success.php");
}
else {
echo "Wrong Username or Password";
}
?>
 
Status
Not open for further replies.

Users who are viewing this thread

Top