getting specific data out of mysql database

I’m a new member here, and also quite new to php - mysql - … so sorry if i say stupid things :slight_smile:

I’ve got a table called “deelnemers” where i store for registered people their “naam”, “voornaam” and “gebruikersnaam” (among other things).
On logging in i store their “gebruikersnaam” in $_SESSION[‘gebuiker’]

Now i want to find the “naam” which corresponds to the “gebruikersnaam” = $_SESSION[‘gebuiker’] in the database.

I use the following code:

[php]<?php
session_start();
include(‘config.php’);
echo $_SESSION[‘gebruiker’];
$gebruiker = $_SESSION[‘gebruiker’];

$db_handle=mysql_connect($db_host,$username,$password);
$db_found=mysql_select_db($db_name,$db_handle);

if(!$db_found){
print “database not found”;
mysql_close($db_handle);
}

$data = mysql_query(“SELECT * FROM deelnemers”);
$info = mysql_fetch_array($data);

$db_field=mysql_fetch_assoc($data);

while($db_field=mysql_fetch_assoc($data)){
if ($db_field[‘gebruikersnaam’] == $gebruiker){
$naamdeelnemer = $db_field[‘naam’];
}
}

echo $naamdeelnemer;
?>[/php]

  1. conifg.php contains the connection parameters, and connection works fine (no error message out of the if-loop)
  2. sessios variables work fine as well (the echo $_SESSION[‘gebruiker’] returns me the given gebruikersnaam
    3
    in the while loop (i think!) i go look row by row if the given “gebruikersnaam” ($gebruiker) matches the “gebruikersnaam” in the database, if so, i put the value of the “naam” in that same row in the variable $naamdeelnemer.

But the echo $naamdeelnmer won’t give me any output…

Can anyone help me with this?
Thanks in advance!

just use a select query:

[php]$query = “SELECT * FROM deelnemers WHERE gebruikersnaam=’{$_SESSION[‘gebuiker’]}’”;[/php]

Thanks a lot, that did the job!!
I’m always messing around with the syntax and the " and ’ … :slight_smile:

Sponsor our Newsletter | Privacy Policy | Terms of Service