Jump to content

need help in mysql_fetch_assoc()


doforumda

Recommended Posts

hi i have a code. the problem with that is when i select all data from table and put only firstname and lastname in a variables it then says these errors

Notice: Undefined variable: firstname in C:\wamp\www\folder\member.php on line 12

Notice: Undefined variable: lastname in C:\wamp\www\folder\member.php on line 12
Welcome, to the member page!

 

my code is here

<?php 
session_start();

include('dbConnect.php');
$getNames = mysql_query("SELECT * FROM basicinfo WHERE userid='$_SESSION[userid]'") or die(mysql_error());

while($names = mysql_fetch_assoc($getNames)) {
$firstname = $names['firstname'];
$lastname = $names['lastname'];
}

echo "Welcome, ".$firstname." ".$lastname." to the member page!";
?>

 

where am i making mistake?

Link to comment
https://forums.phpfreaks.com/topic/191233-need-help-in-mysql_fetch_assoc/
Share on other sites

Are the database fields called firstname and lastname or are you getting any  error from mysql_fetch_assoc?

 

change this

while($names = mysql_fetch_assoc($getNames)) {

  $firstname = $names['firstname'];

  $lastname = $names['lastname'];

 

to this

 

while($names = mysql_fetch_assoc($getNames))

{

  print_r($names);

  $firstname = $names['firstname'];

  $lastname = $names['lastname'];

 

to see what you are getting

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.