Solarpitch Posted June 2, 2007 Share Posted June 2, 2007 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(); Link to comment https://forums.phpfreaks.com/topic/53922-solved-problem-assigning-a-value-to-a-session-variable/ Share on other sites More sharing options...
papaface Posted June 2, 2007 Share Posted June 2, 2007 Do you have session_start(); at the top of the page? Link to comment https://forums.phpfreaks.com/topic/53922-solved-problem-assigning-a-value-to-a-session-variable/#findComment-266611 Share on other sites More sharing options...
Solarpitch Posted June 2, 2007 Author Share Posted June 2, 2007 Yeah I do ... It works with a different session ie.. $_SESSION['name'] = $name; Link to comment https://forums.phpfreaks.com/topic/53922-solved-problem-assigning-a-value-to-a-session-variable/#findComment-266613 Share on other sites More sharing options...
ToonMariner Posted June 2, 2007 Share Posted June 2, 2007 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(); } ?> Link to comment https://forums.phpfreaks.com/topic/53922-solved-problem-assigning-a-value-to-a-session-variable/#findComment-266616 Share on other sites More sharing options...
Solarpitch Posted June 2, 2007 Author Share Posted June 2, 2007 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!"; } } Link to comment https://forums.phpfreaks.com/topic/53922-solved-problem-assigning-a-value-to-a-session-variable/#findComment-266618 Share on other sites More sharing options...
Solarpitch Posted June 2, 2007 Author Share Posted June 2, 2007 Excellent . . got it to work.. I changed if ( @mysql_num_rows($result) > 0 ) to if ( @mysqli_num_rows($result) > 0 ) Thanks for the help! Link to comment https://forums.phpfreaks.com/topic/53922-solved-problem-assigning-a-value-to-a-session-variable/#findComment-266622 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.