Page 1 of 1

Problem with connection to different DB

Posted: Tue Jun 12, 2007 7:18 pm
by thefreebielife
this is the first time ive done this- connect to a different DB on a server.

It didnt turn out so well. none of the info is displaying, only saying "there are no users". what did i do wrong?

Code: Select all

<?
$link = mysql_connect('mysql14.powweb.com', 'aa', 'aa');
if (!$link) {
    die('Could not connect: ' . mysql_error());
}
$db_selected = mysql_select_db('a100');
if (!$db_selected) {
    die('Could not select database: ' . mysql_error());
}
$query = 'SELECT username, ostatus FROM users';
$result = mysql_query($query);
if (!$result) {
    die('Query failed: ' . mysql_error());
} 

mysql_free_result($result);
?>
		      <tr bgcolor="#<?= ($i%2) ? 'FFE5B7' : 'FFEECC' ?>">
		      <Td>
		      <? echo $r["username"]; ?></Td>
		      <Td>
		      <? echo $r["ostatus"]; ?></Td>

<? 
			 if($i==0)
{
?>
 		      <tr>
		      <Td colspan=4 align="center"><FONT SIZE="2" COLOR="#FF0000"><B>No Users Reported</B></FONT></Td>
		      </tr>

<? } ?>  
feel free to laugh, i know this is a stupid problem but please help

Posted: Tue Jun 12, 2007 7:30 pm
by aaronhall
Where are $i and $r being assigned?

Posted: Tue Jun 12, 2007 7:42 pm
by thefreebielife
well even with this code it shows nothing:

Code: Select all

<?
$link = mysql_connect('mysql14.powweb.com', 'a100', 'a100');
if (!$link) {
    die('Could not connect: ' . mysql_error());
}
$db_selected = mysql_select_db('a100');
if (!$db_selected) {
    die('Could not select database: ' . mysql_error());
}
$query = 'SELECT username, ostatus FROM users';
$result = mysql_query($query);
if (!$result) {
    die('Query failed: ' . mysql_error());
} 

mysql_free_result($result);
?>
		      <tr bgcolor="#<?= ($i%2) ? 'FFE5B7' : 'FFEECC' ?>">
		      <Td>
		      <? echo $r["username"]; ?></Td>
		      <Td>
		      <? echo $r["ostatus"]; ?></Td>

Posted: Tue Jun 12, 2007 7:46 pm
by aaronhall
I still don't see where are the variables $i and $r being assigned in your script?

Posted: Tue Jun 12, 2007 7:50 pm
by thefreebielife
im using $r as a result function. $i was an error

Posted: Tue Jun 12, 2007 7:59 pm
by aaronhall
Where are you setting them though? They don't get assigned automatically

Posted: Tue Jun 12, 2007 8:06 pm
by thefreebielife
i guess nowhere?

it seemed to work for me before though..

Posted: Tue Jun 12, 2007 9:41 pm
by Benjamin
thefreebielife wrote:it seemed to work for me before though..
When there were 0 records in the table it worked?