By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,915 Members | 1,362 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,915 IT Pros & Developers. It's quick & easy.

help with post global

100+
P: 348
I have been at this for about 2 days now. I have 2 files. An index file with most of my php and another file with other php and mysql stuff in it.

the mysql query in the (we'll call it 2.php) 2.php file gathers the data from the db for an insert on a particualr customer. I am trying to post the customer number in the form like this

$_POST['customer_number'] = $data['customer_number'];
echo $_POST['customer_number'];

output would be "2", correct.

I cannot get this post var to work in the index file even though I have included 2.php in the index file. <removed>? I'm sorry, I have been at this for 2 days now and I don't get it. I have used post vars and included them in other files and they are there.

Can someone tell me what is wrong? I can make this work putting that needed var into a session but I would rather not do that. I will if it my only option.
Oct 20 '07 #1
Share this Question
Share on Google+
3 Replies


100+
P: 348
fjm
Anyone at all have any clue?
Oct 20 '07 #2

MarkoKlacar
Expert 100+
P: 296
Hi,

is it possible for you to post some code, did not get what it is you want the index file to do.

Cheers
Oct 22 '07 #3

Atli
Expert 5K+
P: 5,058
Hi.

Not knowing exactly how your code looks, I would suggest using the $GLOBALS array. That way you can access the variable anywhere in your code.

For example:
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $GLOBALS['name'] = "James";
  3. class Tester {
  4.   function Print() {
  5.     echo $GLOBALS['name'];
  6.   }
  7. }
  8. $obj = new Tester();
  9. $obj->Print();
  10. ?>
  11.  
Will print 'James'.

You can also consider using the global keyword:
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $name = "James";
  3. class Tester {
  4.   function Print() {
  5.     global $name;
  6.     echo $name;
  7.   }
  8. }
  9. $obj = new Tester();
  10. $obj->Print();
  11. ?>
  12.  
Oct 23 '07 #4

Post your reply

Sign in to post your reply or Sign up for a free account.