Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > Beginning PHP
| Search | Today's Posts | Mark Forums Read
Beginning PHP Beginning-level PHP discussions. More advanced coders should post to the Pro PHP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning PHP section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old January 1st, 2005, 09:32 AM
Authorized User
 
Join Date: Jun 2003
Location: , , .
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
Default Assign value of variables disappearing

hi all,

i have assign a value to a variable but when i try to call it at the end of the program it simply disappear.

i have try echoing out the value in sections of the program and it work but when it comes to tat particular part it just disappear...

have any1 encounter this problem b4?
i am just stuck here...
  #2 (permalink)  
Old January 1st, 2005, 02:06 PM
Friend of Wrox
 
Join Date: Nov 2003
Location: , , .
Posts: 1,285
Thanks: 0
Thanked 2 Times in 2 Posts
Default

Please explain in more detail, or give some of your code.

So, when you try to echo the value at the end, it returns undefined?

Perhaps it is in a function. With a function you must declare that the variable is global, at the beginning of the function.

Code:
$var1 = "hello";

function sayHello()
{
  echo $var1; //will give an undefined notice
}

function globalHello()
{
  global $var1;
  echo $var1; //will give "hello"
}
-Snib - http://www.snibworks.com
Where will you be in 100 years?
  #3 (permalink)  
Old January 1st, 2005, 10:47 PM
Friend of Wrox
 
Join Date: Aug 2004
Location: , , .
Posts: 117
Thanks: 0
Thanked 2 Times in 2 Posts
Default

hi
The old way is like this

$var1 = "hello";
function globalHello($var1)
{
  echo $var1; //will give "hello"
}

Thanks
Regards
Mani_he

  #4 (permalink)  
Old January 2nd, 2005, 07:51 AM
Authorized User
 
Join Date: Jun 2003
Location: , , .
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
Default

hi,

thanks for all the help. :)
i've figured it out.

i rewrote the whole page and it work out.
don't know why it is so but it WORK! :D

thanks all.


Similar Threads
Thread Thread Starter Forum Replies Last Post
disappearing spaces gezi XSLT 0 March 26th, 2006 02:23 AM
Session variables are disappearing? LamivNahdus PHP How-To 0 November 25th, 2005 11:27 AM
Disappearing wizards BlacKnight Access 3 January 19th, 2005 04:35 PM
disappearing cookie droth BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 3 October 28th, 2004 09:24 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.