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
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"];

      }

}

Link to comment
Share on other sites

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>";

Link to comment
Share on other sites

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);

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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