Forum Moderators: coopster

Message Too Old, No Replies

variables

         

pianodevil

4:24 pm on May 26, 2005 (gmt 0)

10+ Year Member



alright, in the form from the previous page, the variables A, B, and C are posted

in the current page, i would like a variable R in the format of A/B/C

for example: if A's value was 12, B's value was 3, and C's value was 10, R would be: 12/3/10

here is wat i have, what have i done wrong?
<?php
$R = '$_POST['A']' + '/' + '$_POST['B']' + '/' + '$_POST['C']';

echo $R;
?>

StupidScript

5:03 pm on May 26, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Oh you Javascripters! ;)

Its two things: the syntax you're using to identify the new variable's elements and the method you're attempting to use for concatenation.

$R = $_POST['A']."/".$_POST['B']."/".$_POST['C'];

echo $R;

$_POST[]
is an array.
$_POST['A']
is an element of that array, not a string, so it doesn't get quoted.
/
is a string element. Also, be careful with using single-quotes instead of double-quotes, as in PHP single-quotes (apostrophes) can cause an object to be created, depending on where and how they are used. Neat, huh?

Welcome to PHP, where all things old are new again!

ergophobe

5:09 pm on May 26, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



[edit]SS beat me to it[/edit]

You've done two things wrong
- you've enclosed the variables in single quotes
- you've used the wrong operator for concatenation

You want:

$R = $_POST['A'] . '/' . $_POST['B'] . '/' . $_POST['C'];