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(); Quote Link to comment 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? Quote Link to comment 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; Quote Link to comment 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(); } ?> Quote Link to comment 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!"; } } Quote Link to comment 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! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.