Jump to content

[SOLVED] Problem assigning a value to a Session Variable.


Solarpitch

Recommended Posts

Hey Guys,

 

Below is a snippet of code that I ma having the problem with. I need to to get the user id from the database and assign it to $_SESSION['user_id'];

 

.... but it doesnt seem to be playing ball!

 


//Connect and stuff....

$query = "select count(*) from members where username = '$nme' and user_password = '".md5($pass)."'";


		  

    $result = mysqli_query( $mysql, $query );
    if(!$result)
    {
      echo 'Cannot run query.';
      exit;
    }
    $row = mysqli_fetch_row( $result );
    $count = $row[0];


    
    if ( $count > 0 )
    {


$user_id = $row['id'];

$_SESSION['user_id'] = $user_id;


  
  
   header("Location:upload.php");
   
   
   
   ob_end_flush();

the 'select count(*)' is your problem

 

change your code to this...

<?php
//Connect and stuff....

$query = "select * from members where username = '$nme' and user_password = '".md5($pass)."'";

     $result = mysqli_query( $mysql, $query ) or die('Cannot run query.');
    
    if ( @mysql_num_rows($result) > 0 )
    {
    $row = mysqli_fetch_assoc( $result );

$_SESSION['user_id'] = $row['id'];	
  
   header("Location:upload.php");
   
   ob_end_flush();
    }
?>

 

Thats what I have no w. . but seems to output "Invalid username or password" even when I enter in the correctcredentials

 

$result = mysqli_query( $mysql, $query ) or die('Cannot run query.');
    
    if ( @mysql_num_rows($result) > 0 )
    {
    $row = mysqli_fetch_assoc( $result );

$_SESSION['user_id'] = $row['id'];
    


$user_id = $row['id'];
$_SESSION['user_id'] = $user_id;


  
  
   header("Location:upload_new_ad.php");
   
   
   
   ob_end_flush();
  
  
        }
        else
	{

        $invalid = "Invalid username or password!";

	}
    }

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.