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:

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

I can’t fetch the data

&lt;?php
session_start();
include 'core/connect.php';
	
	$id = $_GET['id'];

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

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

Substituting some unlikely values, the link looks like

<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.

It seems you forget to bind the id’s value,like


$query->bindValue(':id', $id);

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

&lt;?php
session_start();
include 'core/connect.php';

    $id = $_GET['id'];

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

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

	&lt;a href="profiles.php?=&lt;?php echo $rows['id']?&gt;"&gt; &lt;?php echo $rows['firstname'], ' ', $rows['lastname']?&gt; &lt;br /&gt;&lt;br /&gt; &lt;/a&gt;

Are you using $_GET or $_POST, should be one or the other, not both.

You almost had it. Forgot the execute call.


    $id = $_GET['id']; 

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

    foreach($rows AS $row){ 
        echo $row['notes']; 
    } 

http://www.php.net/manual/en/class.pdostatement.php

( ! ) Parse error: syntax error, unexpected ‘;’ in C:\wamp\www\loaders.php on line 13

with that code :frowning:

Missing a parens, they have to be in pairs.

$query->execute(array('id' => $id));