Jump to content

whats wrong with my code ?


Alicia

Recommended Posts

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 :

[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
[/code]

please advise.
Link to comment
Share on other sites

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

$row_check1 = mysql_fetch_array($check1);
[/code]
Link to comment
Share on other sites

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 [b]MySQL Data Retrieval[/b] section for example code of getting data from MySQL with error checking after every MySQL command.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.