famous58 Posted May 19, 2006 Share Posted May 19, 2006 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? Quote Link to comment https://forums.phpfreaks.com/topic/10019-weird-goings-on/ Share on other sites More sharing options...
kenrbnsn Posted May 19, 2006 Share Posted May 19, 2006 Use the mysql_fetch_assoc() function, not the mysql_fetch_row() function.Ken Quote Link to comment https://forums.phpfreaks.com/topic/10019-weird-goings-on/#findComment-37206 Share on other sites More sharing options...
famous58 Posted May 19, 2006 Author Share Posted May 19, 2006 [!--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.... Quote Link to comment https://forums.phpfreaks.com/topic/10019-weird-goings-on/#findComment-37208 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.