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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing MySQL field 1

Status
Not open for further replies.

humbleprogrammer

Programmer
Oct 30, 2002
315
US
Hello,

I am probably missing something obvious but can someone please help me trouble shoot this code. I am trying to pass the office value stored in the table in the querystring but it's not working. Thanks in advance!

Code:
<?php
	include(&quot;Connection.php&quot;);
	$strQuery = &quot;SELECT * FROM tblUsers WHERE username = '&quot;.$frmUsername.&quot;' AND password = '&quot;.$frmPassword.&quot;'&quot;;
	$row = mysql_query($strQuery) or die(&quot;Error&quot;.mysql_error());
	$office=$row['office'];
	if(mysql_num_rows($row)) {
	
		print(&quot;<br><br><b>Welcome, $frmUsername!<br><br><a href=dateselection.php?username=$frmUsername&office=$office>CLICK HERE</a> to view the reports for your office&quot;);
		
	} 
	
	else {
	 	print(&quot;<br><br><b>Sorry, this login is invalid!</b><br><br>Please <a href='login.php'>GO BACK</a> and try again.&quot;);
	exit;
	}		
?>

 
Hello - thanks for your response. The query outputs correctly and I ran the sql statement in PhpAdmin and it returned the correct result. I did a print command for $strQuery and also $office to see what it returned. $strQuery displayed the correct sql statement but $office didn't display anything. Any ideas?

Thanks!

 
Part of it is that you missed one of the steps for making MySQL data available to PHP -- you never fetched the result set from the database server.

Somewhere between these two lines:

Code:
$row = mysql_query($strQuery) or die(&quot;Error&quot;.mysql_error());
$office=$row['office'];

You need to invoke one of PHP's mysql_fetch_*() functions: mysql_fetch_row(), mysql_fetch_assoc{}, mysql_fetch_array(), or mysql_fetch_object().

Without that, the data will just sit on the MySQL server side, unavailable to PHP.


Want the best answers? Ask the best questions: TANSTAAFL!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top