Jump to content

[SOLVED] calling function not working


aebstract

Recommended Posts

function grabMemDetails (){

global $db;
$result = mysql_query("SELECT * FROM p_users WHERE id='$_SESSION[id]'") or DIE(mysql_error());

      while($r=mysql_fetch_array($result))
      {

      $email=$r["email"];
      $firstname=$r["firstname"];
      $lastname=$r["lastname"];
      $address=$r["address"];
      $city=$r["city"];
      $state=$r["state"];
      $zip=$r["zip"];
      $phone=$r["phone"];
      $pwhint=$r["pwhint"];
      $baddress=$r["baddress"];
      $bstate=$r["bstate"];
      $bcity=$r["bcity"];
      $bzip=$r["bzip"];
      $companyid=$r["companyid"];
      $middleinitial=$r["middleinitial"];
      $registerdate=$r["registerdate"];

      }

}

 

 

<?php
session_start();
header("Cache-control: private");
if(!isset($_SESSION["id"]))
{
header("Location: index.php?page=login");
}













grabMemDetails();


$content .= "<div id=\"full_content\">

<p>Welcome, $firstname $lastname</p>

</div>";



?>

 

$firstname and $lastname are not displaying, any idea why?

Link to comment
https://forums.phpfreaks.com/topic/143922-solved-calling-function-not-working/
Share on other sites

Should this not work?

function grabMemDetails (){

global $db;
$result = mysql_query("SELECT * FROM p_users WHERE id='$_SESSION[id]'") or DIE(mysql_error());

          global $email, $firstname, $lastname, $addres, $city, $state, $zip, $phone, $cell, $pwhint, $baddress, $bstate, $bcity, $bzip, $companyid, $middleinitial, $registerdate;

     while($r=mysql_fetch_array($result))
      {


      $email=$r["email"];
      $firstname=$r["firstname"];
      $lastname=$r["lastname"];
      $address=$r["address"];
      $city=$r["city"];
      $state=$r["state"];
      $zip=$r["zip"];
      $phone=$r["phone"];
      $cell=$r["cell"];
      $pwhint=$r["pwhint"];
      $baddress=$r["baddress"];
      $bstate=$r["bstate"];
      $bcity=$r["bcity"];
      $bzip=$r["bzip"];
      $companyid=$r["companyid"];
      $middleinitial=$r["middleinitial"];
      $registerdate=$r["registerdate"];

      }

}

it might work...but that is a horrible way of doing it. why not something MUCH simpler like this:

function grabMemDetails (){
  global $db;
  $result = mysql_query("SELECT * FROM p_users WHERE id='$_SESSION[id]' LIMIT 1") or DIE(mysql_error());
  return mysql_fetch_assoc($result);
}
$details = grabMemDetails();

$content .= "<div id=\"full_content\">

<p>Welcome, {$details['firstname']} {$details['lastname']}</p>

</div>";

what does this output:

function grabMemDetails (){
  global $db;
  $result = mysql_query("SELECT * FROM p_users WHERE id='$_SESSION[id]' LIMIT 1") or DIE(mysql_error());
  if(!mysql_num_rows($result)) die("User not found");
  return mysql_fetch_assoc($result);
}
$details = grabMemDetails();
print_r($details);

The session id is set, I logged out and back in and the variables showed up, I browsed around and went back and it had the same error. I echoed the id and it had gone from its start point of 1 to 5 by time I got back to the page. I just have to look around and see what is making it increase.

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.