Welcome to WebmasterWorld Guest from 54.221.131.67

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Variables in PHP

Newbie here..scratching my head!

     
10:36 am on Mar 14, 2012 (gmt 0)

Preferred Member

10+ Year Member

joined:May 23, 2002
posts: 446
votes: 0


Hi

I'm completely new to PHP and having been trying to do something that I could do easily in other languages. Please help.

I'm working on a WordPress website and would like like to set a variable in each POST and that variable be inserted to a piece of PHP that's included when the POST is loaded.

For example:

In a POST for Ireland, I'd like to have a variable called $city set to DUBLIN and in the PHP there'd be a line like this:

<script type="text/javascript">
ENG.THISCITY($city)
</script>

I can't get it to work!?!?

Any ideas?

Thanks

Mick
12:54 pm on Mar 14, 2012 (gmt 0)

Senior Member

joined:Nov 12, 2005
posts:5967
votes: 0


Are you printing this as a string in PHP?

e.g:

<script type="text/javascript">
ENG.THISCITY(<?php echo $city; ?>)
</script>
1:19 pm on Mar 14, 2012 (gmt 0)

Senior Member

WebmasterWorld Senior Member 5+ Year Member

joined:May 6, 2008
posts:2011
votes: 0


You have to get the POST variable as well that you sent.

$city = $_POST['city'];
2:23 pm on Mar 14, 2012 (gmt 0)

Preferred Member

10+ Year Member

joined:May 23, 2002
posts: 446
votes: 0


Thanks guys, worked a treat.

All the best