SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast
    Join Date
    Mar 2002
    Location
    Florida
    Posts
    37
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Help Me: Works For Some People, but not others!

    For some people this code works like regular and displays the item info, yet for others it says they don't own the item! I'm getting confused because it works fine for me. I went on my friends computer and all her items worked fine except for one. Wchich is why I'm getting confused, for some people none work!

    PHP Code:
    <?php
    include('background.php');
        
    $id $_GET['id'];
        
    $dbh mysql_connect ("localhost""magicpet_Merlins""password") or die ('I cannot connect to the database.');
    mysql_select_db("magicpet_net");  

    $result mysql_query("SELECT * FROM items WHERE itemid = $id");
    $info mysql_fetch_array($result);
    $user $info[username]; 

        
    $usernname $_COOKIE['magic_pets_username'];

       if(
    "$usernname== "$user"){
     echo 
    "<center><img src=$info[item].jpg><br>";

    <
    item info here>

    }
    else{
    echo 
    "<center>You Dont Own This Item";
    }
    ?>
    Merlinsrealm
    Magic Pets

  2. #2
    SitePoint Evangelist goughb's Avatar
    Join Date
    Sep 2000
    Location
    Chicago
    Posts
    526
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Merlinsrealm,

    Ok lets take a look

    Verify you can select the database change this:
    PHP Code:
    mysql_select_db("magicpet_net"); 
    To this:
    PHP Code:
    if(!mysql_select_db("magicpet_net")); 
     die(
    "didn't work"
    Do the same for this to verify the query is ok:
    PHP Code:
    $result mysql_query("SELECT * FROM items WHERE itemid = $id"); 
    This line confused me what is username? Is that the indice?
    PHP Code:
    $user $info[username]; 
    Why the quotes around the two variables?
    PHP Code:
    if("$usernname== "$user"){ 
    lastly.. if there is a field username in your database why not get the username from the cookie then use it in your query:


    "SELECT * FROM items WHERE itemid = $id" AND username='$user');"


    does any of this help?

    -Brett

  3. #3
    SitePoint Enthusiast
    Join Date
    Mar 2002
    Location
    Florida
    Posts
    37
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Thanks

    It worked
    Merlinsrealm
    Magic Pets


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
  •