Jump to content


Photo

whats wrong with my code ?


  • Please log in to reply
2 replies to this topic

#1 Alicia

Alicia
  • Members
  • PipPipPip
  • Advanced Member
  • 163 posts

Posted 17 May 2006 - 05:46 AM

Hi,

Can somebody give me an idea why nothing is displayed when i try to output the last login and ip value by using this code :

$check1 = mysql_query("SELECT * FROM `log` WHERE `username`='$username'") or die(mysql_error());
    $row_check1 = mysql_fetch_row($check1);
    $last_login = $row_check1['latest_login'];
    $last_login_ip = $row_check1['lastest_login_ip'];


    echo "< $last_login | $last_login_ip >";
// nothing is displayed ... the variables name are used correctly 

please advise.

#2 alpine

alpine
  • Members
  • PipPipPip
  • Advanced Member
  • 756 posts
  • LocationNorway

Posted 17 May 2006 - 06:04 AM

assuming you have $username set previously in your code, try mysql_fetch_array() instead of mysql_fetch_row()
// $row_check1 = mysql_fetch_row($check1);

$row_check1 = mysql_fetch_array($check1);


#3 toplay

toplay
  • Staff Alumni
  • Advanced Member
  • 973 posts

Posted 17 May 2006 - 06:20 AM

Good point Alpine. However, I would go a step further and say use mysql_fetch_assoc() which returns an associated array (which is all you're using).

You should also check after the fetch if any data was returned. Don't assume it did. The query might not give any errors and the fetch returns no data. This is not an error or problem but simply that it means there was no data that met the search criteria.

FYI:

Click on the [a href=\"http://www.phpfreaks.com/forums/index.php?showtopic=31047&view=findpost&p=153359\" target=\"_blank\"]PHP F.A.Q.[/a] link. Find and read the MySQL Data Retrieval section for example code of getting data from MySQL with error checking after every MySQL command.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users