SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member
    Join Date
    Feb 2002
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Using Database [id]

    Hello all,
    I am so very new at this PHP thing and I have set up my database through myPHPAdmin, however I am having a great deal of trouble calling the file as I would like. I'm making a lyrics site and when I link to lyrics.php?id=005, I want whatever lyric is 005 to show up on my page. I'm trying to use the following:

    <?php
    $id = $HTTP_GET_VARS['id'];
    $sql = "SELECT lyrics FROM Lyrics_table WHERE id=$id";
    $result = mysql_query($Lyrics);
    ?>

    Any help would be greatly appreciated. Thank you.

  2. #2
    I have an opinion...
    Join Date
    Sep 2001
    Location
    Barrie, Ontario
    Posts
    324
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Assuming that you have already made your database connection, selected the proper database, etc, then try this:

    PHP Code:
    $id $HTTP_GET_VARS["id"];
    if( 
    is_numeric$id ) ) { 
        
    $sql "SELECT lyrics FROM Lyrics_table WHERE id=" $id;
        
    $result mysql_query$sql ) or die( mysql_error() );

    Egotist: A person more interested in himself than in me.
    KodeKrash - Eidix - Barrie LUG

  3. #3
    Making a better wheel silver trophy DR_LaRRY_PEpPeR's Avatar
    Join Date
    Jul 2001
    Location
    Missouri
    Posts
    3,428
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i'd do it like this with a bit less code (instead of the is_numeric() thing):

    PHP Code:
    $id = (int) $HTTP_GET_VARS['id'];
    $sql "SELECT lyrics FROM Lyrics_table WHERE id=$id";
    $result mysql_query($sql) or die(mysql_error());
    $row mysql_fetch_array($result);

    echo 
    $row['lyrics']; 
    - Matt ** Ignore old signature for now... **
    Dr.BB - Highly optimized to be 2-3x faster than the "Big 3."
    "Do not enclose numeric values in quotes -- that is very non-standard and will only work on MySQL." - MattR

  4. #4
    SitePoint Member
    Join Date
    Feb 2002
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    is 'id' case sensitive in the DB

    I had to change my lowercase id to uppercase ID and I was able to pull a list of items in my database.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •