SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Member Godz06's Avatar
    Join Date
    Nov 2013
    Posts
    12
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    Unhappy grabbing data from DB

    I'm trying to grab information for a user and displaying it on their profile, but this isn't working. what am I doing wrong? and how i can correct it?

    after I clicking on the user link:
    PHP Code:
    <a href="profiles.php?=<?php echo $rows['id']?>"> <?php echo $rows['firstname'], ' '$rows['lastname']?> <br /><br /> </a>

    I can't fetch the data

    PHP Code:
    <?php
    session_start
    ();
    include 
    'core/connect.php';
        
        
    $id $_GET['id'];

        
    $query dbConnect()->prepare("SELECT `id`, `firstname`, `lastname`, `notes` FROM `loaders` WHERE id = :id");

        foreach(
    $query->fetchAll(PDO::FETCH_ASSOC) AS $rows){
            echo 
    $rows['notes'];
        }
        
    ?>

  2. #2
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,147
    Mentioned
    190 Post(s)
    Tagged
    2 Thread(s)
    Substituting some unlikely values, the link looks like
    HTML Code:
    <a href="profiles.php?=1234"> god z06 <br /><br /> </a>
    I see a Get value but no name (id), and the break tags inside the link don't look right.

  3. #3
    SitePoint Member
    Join Date
    Dec 2013
    Posts
    20
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It seems you forget to bind the id's value,like
    Code:
    $query->bindValue(':id', $id);

  4. #4
    SitePoint Member Godz06's Avatar
    Join Date
    Nov 2013
    Posts
    12
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    I'm getting errors:

    Notice: Undefined Index: Id In C:\Wamp\Www\Loaders.Php On Line 10
    Notice: Undefined Index: Firstname In C:\Wamp\Www\Loaders.Php On Line 14
    Notice: Undefined Index: Firstname In C:\Wamp\Www\Loaders.Php On Line 15
    Notice: Undefined Index: Notes In C:\Wamp\Www\Loaders.Php On Line 16

    PHP Code:
    <?php 
    session_start
    (); 
    include 
    'core/connect.php'
         
        
    $id $_GET['id']; 

        
    $query dbConnect()->prepare("SELECT `id`, `firstname`, `lastname`, `notes` FROM `loaders` WHERE id = :id"); 
        
    $query->bindValue(':id'$id);
        
    $query->bindValue(':firstname'$_POST['firstname']);
        
    $query->bindValue(':lastname'$_POST['lastname']);
        
    $query->bindValue(':notes'$_POST['notes']);
        
    $query->execute();

        foreach(
    $query->fetchAll(PDO::FETCH_ASSOC) AS $rows){ 
            echo 
    $rows['notes']; 
        } 
        
    ?>

        <a href="profiles.php?=<?php echo $rows['id']?>"> <?php echo $rows['firstname'], ' '$rows['lastname']?> <br /><br /> </a>

  5. #5
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,147
    Mentioned
    190 Post(s)
    Tagged
    2 Thread(s)
    Are you using $_GET or $_POST, should be one or the other, not both.

  6. #6
    SitePoint Guru
    Join Date
    Nov 2003
    Location
    Huntsville AL
    Posts
    689
    Mentioned
    4 Post(s)
    Tagged
    0 Thread(s)
    You almost had it. Forgot the execute call.
    PHP Code:
        $id $_GET['id']; 

        
    $query dbConnect()->prepare("SELECT `id`, `firstname`, `lastname`, `notes` FROM `loaders` WHERE id = :id"); 
        
    $query->execute(array('id' => $id);
        
    $rows $query->fetchAll(PDO::FETCH_ASSOC);

        foreach(
    $rows AS $row){ 
            echo 
    $row['notes']; 
        } 
    http://www.php.net/manual/en/class.pdostatement.php

  7. #7
    SitePoint Member Godz06's Avatar
    Join Date
    Nov 2013
    Posts
    12
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    ( ! ) Parse error: syntax error, unexpected ';' in C:\wamp\www\loaders.php on line 13
    with that code

    Quote Originally Posted by ahundiak View Post
    You almost had it. Forgot the execute call.
    PHP Code:
        $id $_GET['id']; 

        
    $query dbConnect()->prepare("SELECT `id`, `firstname`, `lastname`, `notes` FROM `loaders` WHERE id = :id"); 
        
    $query->execute(array('id' => $id);
        
    $rows $query->fetchAll(PDO::FETCH_ASSOC);

        foreach(
    $rows AS $row){ 
            echo 
    $row['notes']; 
        } 
    http://www.php.net/manual/en/class.pdostatement.php

  8. #8
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,147
    Mentioned
    190 Post(s)
    Tagged
    2 Thread(s)
    Missing a parens, they have to be in pairs.
    PHP Code:
    $query->execute(array('id' => $id)); 


Tags for this Thread

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
  •