Page 1 of 2

Getting error for query

Posted: Sat Jun 09, 2007 10:32 pm
by thefreebielife

Code: Select all

<table style="border:1px solid #0099CC; width:735px; font-size:12px; margin-left:30px;" cellpadding="2" cellspacing="0">
	<tr>
	<td colspan="3" style="border-bottom:1px solid #0099CC"><div align="center"><strong>Your Manual Credit Requests </strong></div></td>
	</tr>
	<tr bgcolor="#CCEAEA">
	<td width="25%" style="border-bottom:1px solid #0099CC"><div align="center">uId </div></td>
	<td width="50%" style="border-bottom:1px solid #0099CC"><div align="center">Name</div></td>
	<td width="25%" style="border-bottom:1px solid #0099CC"><div align="center">email</div></td>
	</tr>
	<?

	$sql = "SELECT * FROM cash1.. users, freebie.. users where username='" . $_SESSION['username'] . "' order by status DESC, uId DESC";
	$result = mysql_query($sql);
	$i=0;
	while($r=mysql_fetch_array($result))
	{	
		$i=$i+1;
		?>
		<tr bgcolor="#<?= ($i++%2) ? 'FFFFFF' : 'F5F5F5' ?>">
		<td width="25%" style="border-bottom:1px dashed orange; border-right:1px dashed orange"><div align="center"><FONT SIZE="2"><? echo $r["uId"]; ?></FONT></div></td>
		<td width="50%" style="border-bottom:1px dashed orange; border-right:1px dashed orange"><div align="left"><FONT SIZE="2">&nbsp;<? echo $r["username"]; ?></FONT></div></td>
		<td width="25%" style="border-bottom:1px dashed orange; border-right:1px dashed orange"><div align="center"><FONT SIZE="2"><? echo $r["email"]; ?></FONT></div></td>
		</tr>  
		<? } 
	if($i==0)
	{
		?>
		<tr>
		<Td colspan=3 align="center"><FONT SIZE="2" COLOR="#FF0000"><B>There are no users</B></FONT></Td>
		</tr>

		<? } ?>


	</table>
errors:
PHP Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /hermes/web10/b257/pow.thefreebielife/cash/htdocs/test1.php on line 23
PHP Warning: mysql_query() [<a href='function.mysql-query'>function.mysql-query</a>]: A link to the server could not be established in /hermes/web10/b257/pow.thefreebielife/cash/htdocs/test1.php on line 21
PHP Warning: mysql_query() [<a href='function.mysql-query'>function.mysql-query</a>]: Access denied for user 'wwwuser'@'cgi0702.int.bizland.net' (using password: NO) in
I dont know what to do as im trying to figure out how to access info from 2 db's. any help would be very appriciated

Posted: Sat Jun 09, 2007 10:41 pm
by John Cartwright
change

Code: Select all

$result = mysql_query($sql);
to

Code: Select all

$result = mysql_query($sql) or die(mysql_error());
For a more informative error

Posted: Sat Jun 09, 2007 10:48 pm
by thefreebielife
Access denied for user 'wwwuser'@'cgi0704.int.bizland.net' (using password: NO)
that comes up on the page

Posted: Sat Jun 09, 2007 11:07 pm
by feyd
Missing or improper mysql_connect() call? Permissions set appropriately for the user?

Posted: Sat Jun 09, 2007 11:10 pm
by thefreebielife
well i have it so "cash1" can log into "freebie" and "freebie" can log into "cash1"

Posted: Sun Jun 10, 2007 12:37 am
by feyd
That may be, but MySQL is saying "wwwuser."

Posted: Sun Jun 10, 2007 8:20 am
by thefreebielife
well i dont have a user called "wwwuser" and i have no idea what "cgi0704.int.bizland.net" is

Posted: Sun Jun 10, 2007 8:23 am
by feyd
Where is your mysql_connect() call?

Posted: Sun Jun 10, 2007 8:27 am
by thefreebielife
well my config file connects to cash1

but i didnt know how to do that using more then one call?

for example, where would the second db need to go in this code:

Code: Select all

<?php
$link = mysql_connect('localhost', 'mysql_user', 'mysql_password');
if (!$link) {
    die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully';
mysql_close($link);
?> 

Posted: Sun Jun 10, 2007 9:40 am
by volka
mysql_close() closes a mysql connection
Therefore

Code: Select all

$link = mysql_connect(...);
// <- error handling ->
mysql_close($link)
doesn't make much sens

Posted: Sun Jun 10, 2007 9:41 am
by thefreebielife
oh well i just found that through the link. but i still dont understand where to put the second connection

Posted: Sun Jun 10, 2007 9:43 am
by volka
...second connection ...sorry, I have no idea what you're asking.

Posted: Sun Jun 10, 2007 10:27 am
by Benjamin
You only need one connection. You aren't locked to one database when you connect. You can specify the database in the query.

Code: Select all

SELECT fieldone, fieldtwo FROM database1.table1 WHERE fieldone > 10

Posted: Sun Jun 10, 2007 10:31 am
by thefreebielife
so the would this be right:

Code: Select all

SELECT username FROM cash1.users WHERE uId = "" 
SELECT username FROM freebie.users WHERE uId = ""
just like that if i want to use 2 separate db's?

Posted: Sun Jun 10, 2007 10:32 am
by Benjamin
Yes.