/    Sign up×
Community /Pin to ProfileBookmark

Change PHP Variable Through HTML?

Hello i am trying to figure out how to change a php variable when a button or link is clicked on the webpage and then reload the page.

i tried something like this

[CODE]<a href=”<?php $var=1 ?>”>button</a>[/CODE]

but it did not work.

to post a comment
PHP

8 Comments(s)

Copy linkTweet thisAlerts:
@MindzaiOct 20.2009 — Every time the page loads the script will start from fresh and not remember any values from last time. Probably the easiest way of persisting data accross pages is via a session.
Copy linkTweet thisAlerts:
@MaaaTtYauthorOct 20.2009 — damn. i also realised what i was doing was only being executed before the page loaded not when a button was clicked ( i dont even know if thats possible). anyways, this is for a project and im not allowed to use a session or GET and POST.
Copy linkTweet thisAlerts:
@criterion9Oct 20.2009 — Are you supposed to use javascript or perhaps a cookie then?
Copy linkTweet thisAlerts:
@MindzaiOct 20.2009 — i also realised what i was doing was only being executed before the page loaded not when a button was clicked[/QUOTE]

Yes, PHP is a server side language. As suggested, it sounds like you'll need to use a client side language such as javascript.
Copy linkTweet thisAlerts:
@YelgnidrocOct 20.2009 — I can't see how you can change a [B]php variable[/B] without using a session, GET or POST. Well, not in any useful way.

You could save the php variable to a database / file / cookie, click a button that will reload the page (or re-direct) and then read back from the database / file /cookie and increment it. This obviously has limitations!!

I don't think that javascript can change php variables.
Copy linkTweet thisAlerts:
@MindzaiOct 21.2009 — I don't think that javascript can change php variables.[/QUOTE]

Not as such, but it can read/write from the same cookies as a PHP script.
Copy linkTweet thisAlerts:
@ehimeOct 21.2009 — I think the best way would be a post, but then

again I don't know what you're trying to change

it to or from?
Copy linkTweet thisAlerts:
@ssystemsOct 21.2009 — I would go for post/session as well.But without a clearer view of what you're trying to achieve we can't really help a lot. Good Luck.
×

Success!

Help @MaaaTtY spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.20,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...