Forum Moderators: coopster

Message Too Old, No Replies

Variables in PHP

Newbie here..scratching my head!

         

giggle

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

10+ Year Member



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

eelixduppy

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



Are you printing this as a string in PHP?

e.g:

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

StoutFiles

1:19 pm on Mar 14, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



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

$city = $_POST['city'];

giggle

2:23 pm on Mar 14, 2012 (gmt 0)

10+ Year Member



Thanks guys, worked a treat.

All the best