Jump to content


Photo

Weird Goings On


  • Please log in to reply
2 replies to this topic

#1 famous58

famous58
  • Members
  • PipPip
  • Member
  • 21 posts

Posted 19 May 2006 - 04:36 PM

So I've been using PHP to query MySQL dbs for a while now and have never had this happen to me. All of a sudden I cannot get the data to display using my normal code.

This no longer works:
<?

mysql_connect("localhost", "db_user", "pass") or die("Could not connect");
mysql_select_db("db_name") or die("Could not select database");

$result = mysql_query("SELECT * FROM `users` WHERE `username`='admin' ") or die(mysql_error());
$row = mysql_fetch_row($result);

echo $row[username]; 

?>

But this does:
<?

mysql_connect("localhost", "db_user", "pass") or die("Could not connect");
mysql_select_db("db_name") or die("Could not select database");

$result = mysql_query("SELECT * FROM `users` WHERE `username`='admin' ") or die(mysql_error());
$row = mysql_fetch_row($result);

echo $row[1]; 

?>

I've triple checked that "username" is "username" in the db. I'm at a total loss. What would cause this all of a sudden?
I'm trying, really I am.

#2 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 19 May 2006 - 04:44 PM

Use the mysql_fetch_assoc() function, not the mysql_fetch_row() function.

Ken

#3 famous58

famous58
  • Members
  • PipPip
  • Member
  • 21 posts

Posted 19 May 2006 - 04:48 PM

[!--quoteo(post=375273:date=May 19 2006, 08:44 AM:name=kenrbnsn)--][div class=\'quotetop\']QUOTE(kenrbnsn @ May 19 2006, 08:44 AM) View Post[/div][div class=\'quotemain\'][!--quotec--]
Use the mysql_fetch_assoc() function, not the mysql_fetch_row() function.

Ken
[/quote]

doh!

I'll crawl back into my hole now....
I'm trying, really I am.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users