Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

mysql_fetch_assoc(): error

Status
Not open for further replies.

leeboycymru

Programmer
Jan 23, 2007
185
GB
I keep getting this error:

mysql_fetch_assoc():supplied argument is not valid MySQL result resource in x on line 24.

And here is that code:

Code:
$cxn = @ConnectToDb(DB_SERVER, DB_SERVER_USERNAME, DB_SERVER_PASSWORD, DB_DATABASE);

	$transLog = mysql_query("select * from tblTransLog where invoiceID = '".$stransID."'");

	$row_transLog = mysql_fetch_assoc($transLog);
	
	switch($row_transLog["transactionStatus"])

I dont know what the problem is, can anybody help?

Thanks

Lee
 
Sorry guys, maybe I should have added the case lines to, so I have added all that code below; because I get second error saying:

Cannot modify header information - headers already sent by (output started at x) on line 50.

So here is all that code:

Code:
$cxn = @ConnectToDb(DB_SERVER, DB_SERVER_USERNAME, DB_SERVER_PASSWORD, DB_DATABASE);

	$transLog = mysql_query("select * from tblTransLog where invoiceID = '".$stransID."'");

	$row_transLog = mysql_fetch_assoc($transLog);
	
	switch($row_transLog["transactionStatus"])
	{
		case "DECLINED":
		{
			header('Location: '.HTTP_SERVER.DIR_WS_CATALOG.'index.php?main_page=checkout_payment');
			break;
		}
		case "An error has occurred. Please contact the merchant and quote Ref 51.":
		{
			header('Location: '.HTTP_SERVER.DIR_WS_CATALOG.'index.php?main_page=checkout_payment');
			break;
		}
		case "There was a Problem processing your order. Please contact the merchant and quote Ref ".$row_transLog["sessionID"]."";
		{
			header('Location: '.HTTP_SERVER.DIR_WS_CATALOG.'index.php?main_page=checkout_payment');
			break;
		}
		case "Success":
		{
			header('Location: '.HTTP_SERVER.DIR_WS_CATALOG.'index.php?main_page=checkout_success');
			break;
		}
		default:
		{
			header('Location: '.HTTP_SERVER.DIR_WS_CATALOG.'index.php?main_page=checkout_payment');
		}
	}

Cheers
 
The header errors mean you have some kind of output before the header calls. You can't have any type of output, that includes html, text, even white pace before the header calls.

As fro the mysql_fetch_assoc problem, its telling you the variable you are using is not a valid resource, which means it contains no results.

Try adding the following to your mysql_query call see if you get more information on why the variable has no resuts:

Code:
$transLog = mysql_query("select * from tblTransLog where invoiceID = '".$stransID."'")[red]or die(mysql_error())[/red];

These are actually PHP errors, so you'd be better off posting the question in forum434

----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top