TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 01-29-2010, 05:36 PM   #1 (permalink)
The Visitor
Newcomer 
 
Join Date: Jan 2010
Posts: 1
Thanks: 0
reverse is on a distinguished road
Default global variables

Hi all,

I need help on this:
How do I pass a value from one variable to another variable upon users click?

example:
I have following html site

Code:
<html>
<head>
</head>
<body>

<?php
myGloablVarA=var1;
myGloablVarB=var2;
myGloablVarC=var3;
?>

<?php
some php codes here

how do make a function here (onclick) change those Global Variable defined above(myGloablVarA,myGloablVarB,myGloablVarC)
to new values thats been generated upon user click?

currently I am posting the value to url location

echo'<a href=\"detail.php?id=$var1.$var2.$var3\">

instead of posting the values to url location I 
would like values to be stored in global varaibles and....
?>

<?php
.....read the values back here again

myVarnew1=myGloablVarA; // assign new values from myGloablVarA
myVarnew2=myGloablVarB;
myVarnew3=myGloablVarC;
?>
</body>
</html>

many thanks..I would be very glad on any tips
reverse
reverse is offline  
Reply With Quote
Old 01-29-2010, 06:00 PM   #2 (permalink)
Wizard
Top Contributor 
 
Village Idiot's Avatar
 
Join Date: Sep 2007
Posts: 1,299
Thanks: 17
Village Idiot is on a distinguished road
Default

You cant. PHP fully executes before the first character of information is sent to the user, so by the time they see it there is nothing running to switch. I also do not think you understand how global variables work. Global variables do not outlast the application which they are defined in, they are deleted along with everything else when the script finishes running.
__________________

Village Idiot is offline  
Reply With Quote
Old 01-30-2010, 09:17 AM   #3 (permalink)
The Wanderer
 
andformore's Avatar
 
Join Date: Dec 2009
Posts: 17
Thanks: 2
andformore is on a distinguished road
Default some basics...

Village Idiot is, of course, right.

I've seen this type of logic from beginners before, and its pretty understandable. What I would recommend to help you better understand what is going on is to divide up your file into two sections, one where you're doing PHP work and the other where you're outputting HTML, sort of like this:

PHP Code:

<?php

//do all your data manipulation here
$someVar $someOtherVar;
$etc....

//then, below here you can put all your html
?>

<html>
<head>
</head>
<body>
<h1>this is an html page.</h1>
the value of a variable prepared above is <?php echo $someVar ?>.
</body>
</html>
Also, you should read a bit about how web servers work in general. The process is typically (for a php file) like:

1. a web user requests a page (www.example.com/myPhpFile.php)
2. the server runs the php file which creates html
3. the server sends that html back to the user who requested it
4. the user's browser turns that html into a working webpage
4. the user will click something which will either request a different page, or it will send a request along with some data. The server will handle that data and then send back the resulting html again.

You'll want to send the data using forms for now
If you let us know a bit more concretely what you want to accomplish we can help a bit more
__________________
Something interesting... If you visit one of my sites today, you'll probably double my unique visitors for the day! Shameless Plugs:
My Blog My Octopus Game My Flash Card Website
andformore is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Defining your World: All About Constants Wildhoney General 15 01-29-2013 12:32 PM
How to transfer javascript variables from one file to another file. sandhyagupta Absolute Beginners 1 08-05-2009 12:02 PM
global variables or not? allworknoplay The Lounge 6 05-25-2009 06:07 AM
Is there a function to list all "active" variables Dave Absolute Beginners 3 06-05-2008 04:03 AM
When was the last time you used the global construct? Wildhoney The Lounge 11 01-28-2008 08:41 PM


All times are GMT. The time now is 07:06 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design