Jump to content

Archived

This topic is now archived and is closed to further replies.

famous58

Weird Goings On

Recommended Posts

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:
[code]
<?

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];

?>
[/code]

But this does:
[code]
<?

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];

?>
[/code]

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?

Share this post


Link to post
Share on other sites
Use the mysql_fetch_assoc() function, not the mysql_fetch_row() function.

Ken

Share this post


Link to post
Share on other sites
[!--quoteo(post=375273:date=May 19 2006, 08:44 AM:name=kenrbnsn)--][div class=\'quotetop\']QUOTE(kenrbnsn @ May 19 2006, 08:44 AM) [snapback]375273[/snapback][/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....

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.