# \[php / mysql\] cannot retrieve table entry

**URL:** <https://forum.kirupa.com/t/php-mysql-cannot-retrieve-table-entry/226914>\
**Category:** programming\
**Created:** [May 25, 2007, 12:50am UTC](https://forum.kirupa.com/t/php-mysql-cannot-retrieve-table-entry/226914 "2007-05-25T00:50:44Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![NeoDreamer](https://avatars.discourse-cdn.com/v4/letter/n/ccd318/32.png) [@NeoDreamer](https://forum.kirupa.com/u/NeoDreamer)\
**Post date:** [May 25, 2007, 12:50am UTC](https://forum.kirupa.com/t/php-mysql-cannot-retrieve-table-entry/226914/1 "2007-05-25T00:50:44Z")

</div>

I’m making a login page. It will save the the user’s name and encrypted password with session variables. For some reason I can’t retrieve anything in the $row variable. As you can see $num is 1, meaning that at least one row was chosen. I have tested the query directly in my phpAdmin control panel and it does turn up a valid row with good info. However, when I upload the page to my host and test it live, it doesn’t work!

code:

```php

// attempt to log-in
$conn = @mysql_connect($DB_SERVER, $DB_USER, $DB_PASSWORD) or die("Could not connect.");
$rs = @mysql_select_db($DB_DB, $conn) or die("Could not select database.");
$sql = 'select id, banned, approved, email, password, username from members where username="'.$username.'" and password = password("'.$password.'")';
$rs = @mysql_query($sql, $conn) or die ("Could not execute query.");
$num = mysql_num_rows($rs);
$row = mysql_fetch_array($rs);

// success if match, not banned, and approved
if(($num == 1) && ($row['banned'] != 1) && ($row['approved'] == 1))
{
	// make cookie
	$row = mysql_fetch_array($rs);
	$_SESSION['id'] = $row['username'];
	$_SESSION['pw'] = $row['password'];
	
        // debugging
	echo('banned is '. $row['banned'] .'<br />');
	echo('approved is '. $row['approved'] .'<br />');
	echo('email is '. $row['email'] .'<br />');
	echo('id is '. $_SESSION['id'] .'<br />');
	echo('pw is '. $_SESSION['pw'] .'<br />'); 
	echo('user is '. $username .'<br />');
	echo('pass is '. $password .'<br />');
	echo('sql is '. $sql .'<br />');
	echo('num is '. $num .'<br />');
}

```

Output:

> 

banned is  
approved is  
email is  
id is  
pw is  
user is myName  
pass is myPass  
sql is select id, banned, approved, email, password, username from members where username=“myName” and password = password(“myPass”)  
num is 1
