1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Whats wrong with this? (searching database for specific id)

Discussion in 'PHP' started by killaklown, Feb 23, 2007.

  1. #1
    This is the code which im having problems with (its not all the code, so i am not missing the <?php, or a })
    SEMrush
    
        $sql_query = "SELECT * FROM links WHERE id='$id'";
        //store the SQL query in the result variable
        $result = mysql_query($sql_query);
    
        if(mysql_num_rows($result))
        {
        //output as long as there are still available fields
        while($row = mysql_fetch_array($result))
        {
            $title = $row["title"];
            $url = $row["url"];
            $id = $row["id"];
            $status = $row["status"];
    		$email = $row["email"];
       }
    
    Code (markup):

    Im trying to get it to let you edit the information in the 'links' part of the database. The page before has this code:

    <a href=\"editlink.php?id=$id\">Edit</a>
    Code (markup):
    The id is right and everything, but the page always shows it as blank. I had it working a long time ago, then kind of forgot about it and now it doesnt work.
     
    killaklown, Feb 23, 2007 IP
    SEMrush
  2. Clive

    Clive Web Developer

    Messages:
    4,507
    Likes Received:
    296
    Best Answers:
    0
    Trophy Points:
    250
    #2
    <a href=\"editlink.php?id=$id\">Edit</a>
    Code (markup):
    Are you using an "echo" to output that part or is that pure html code?
    If it's html, then you need
    <a href=\"editlink.php?id=<?php echo $id ?>\">Edit</a>
    Code (markup):
     
    Clive, Feb 23, 2007 IP
  3. killaklown

    killaklown Well-Known Member

    Messages:
    2,666
    Likes Received:
    87
    Best Answers:
    0
    Trophy Points:
    165
    #3
    yes im using echo.
     
    killaklown, Feb 24, 2007 IP
  4. picouli

    picouli Peon

    Messages:
    760
    Likes Received:
    89
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Try changing this:
    while($row = mysql_fetch_array($result))
    PHP:
    with this:
    while($row = mysql_fetch_assoc($result))
    PHP:
    HTH, cheers! :)
     
    picouli, Feb 24, 2007 IP
  5. toby

    toby Notable Member

    Messages:
    6,923
    Likes Received:
    269
    Best Answers:
    0
    Trophy Points:
    285
    #5
    put a debug statement inside the WHILE loop to see if the $id is showing some value.
     
    toby, Feb 24, 2007 IP
  6. designcode

    designcode Well-Known Member

    Messages:
    738
    Likes Received:
    37
    Best Answers:
    0
    Trophy Points:
    118
    #6
    Trace if $id has some value in it.

    
     print "ID IS " . $id;
     $sql_query = "SELECT * FROM links WHERE id='$id'";
     ..............
    
    PHP:
    If id is empty, then try following code
    
     $id = $_GET['id'];
     $sql_query = "SELECT * FROM links WHERE id='$id'";
     ..............
    
    PHP:
     
    designcode, Feb 24, 2007 IP
  7. DeViAnThans3

    DeViAnThans3 Peon

    Messages:
    785
    Likes Received:
    83
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Probably this is not why your script isn't working, but why do you put this if statement:
     if(mysql_num_rows($result))
    {
    ...
    }
    PHP:
    Maybe it'ld be better to use (because ID is unique, it'll always return the same)
     if(mysql_num_rows($result) > 0)
    {
    ...
    }
    PHP:
    The fact your page is blank, possibly you could try to get all PHP warnings and errors by putting the following code just after <?php at the beginning of the page:
    error_reporting(E_ALL);
    PHP:
    I keep watching this :)
     
    DeViAnThans3, Feb 24, 2007 IP
  8. killaklown

    killaklown Well-Known Member

    Messages:
    2,666
    Likes Received:
    87
    Best Answers:
    0
    Trophy Points:
    165
    #8
    sorry, i fixed it yesturday, i used pretty much what designcode said.
     
    killaklown, Feb 25, 2007 IP
  9. designcode

    designcode Well-Known Member

    Messages:
    738
    Likes Received:
    37
    Best Answers:
    0
    Trophy Points:
    118
    #9
    So wanna add to my rep :D:D
     
    designcode, Feb 25, 2007 IP
    killaklown likes this.
  10. killaklown

    killaklown Well-Known Member

    Messages:
    2,666
    Likes Received:
    87
    Best Answers:
    0
    Trophy Points:
    165
    #10
    uh, i fixed it with help on another forum, but ill give ya some rep ;)
     
    killaklown, Feb 25, 2007 IP
  11. designcode

    designcode Well-Known Member

    Messages:
    738
    Likes Received:
    37
    Best Answers:
    0
    Trophy Points:
    118
    #11
    Thanks buddy :D
     
    designcode, Feb 25, 2007 IP