SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast wallyweb's Avatar
    Join Date
    Oct 2003
    Location
    Saint John, NB, Canada
    Posts
    41
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Why is name undefined?

    Code:
    printf("<a href=\"%s?id=%s&delete=yes\">(DELETE)</a>", $_SERVER['PHP_SELF'], $row['id']);
    jumps to
    Code:
    if(isset($_GET['delete'])){
       $id = $_GET['id'];
       echo $id;
       $query = "SELECT name FROM bands WHERE id=$id";
       if ($result = mysqli_query($dbcnx, $query)){echo $name;}
       $query = "DELETE from bands WHERE id=$id";
       $result = mysqli_query($dbcnx, $query);
    }
    The first echo returns the proper id and the row is deleted but the second echo does not return a value.
    Why do I keep getting Undefined variable: name from the line with the first query?

  2. #2
    SitePoint Zealot
    Join Date
    Aug 2004
    Location
    Madison, WI
    Posts
    191
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    you would have to actually fetch the information out of the result, such as
    PHP Code:
    $row=mysql_fetch_assoc($result);
    echo 
    $row['name']; 

  3. #3
    SitePoint Enthusiast wallyweb's Avatar
    Join Date
    Oct 2003
    Location
    Saint John, NB, Canada
    Posts
    41
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Changed it to
    Code:
    $id = $_GET['id'];
       $query = "SELECT * FROM bands where id=$id";
       if ($result = mysqli_query($dbcnx, $query)){
          $row = mysqli_fetch_array($result, MYSQLI_ASSOC);
          echo $row['name'];
       }
    which is in keeping with your suggestion as well as PHP5 and it works and I thank you very much.
    But I still have to ask why do I have to use the wildcard - * - in the SELECT statement instead of a column name which works in the MySQL DOS box?


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
  •