Forum Moderators: coopster

Message Too Old, No Replies

Form Variables

I am trying to change a variable name in the form output.

         

judson

3:37 pm on Mar 19, 2004 (gmt 0)

10+ Year Member



I have a script that lets users design a sign onlin. The user has the option of border color, if they choose no border, it is supposed to default to the background color. The code looks like this:

if $_POST['bordercolor'] = "none"
then bordercolor = $_POST['bg_color']
else bordercolor = $_POST['bordercolor']

I cannot get it to pass the variable twice, I am assuming this is a PHP limitation. So I tried changing the variable name like so:

$_POST['bordercolor] = &$bordercolor
$_POST['bg_color] = &$background

and changing the code to:

if $_POST['bordercolor'] = "none"
then bordercolor = $background
else bordercolor = $bordercolor

But it does not pass any values, the bordercolor comes back with a value of "". I know the syntax isn't correct, but I type the shortened version for time purposes. Should this work?

Timotheos

4:25 pm on Mar 19, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi judson,

Welcome to WebmasterWorld!

Your if/else control structure has me a little confused. Check it out in the manual [php.net] and you'll see what I mean.

if ($_POST['bordercolor'] == "none") {
$bordercolor = $_POST['bg_color'];
}
else {
$bordercolor = $_POST['bordercolor'];
}

I'm surprised you're not getting some sort of error.

judson

4:54 pm on Mar 19, 2004 (gmt 0)

10+ Year Member



I know the structure isn't correct. I just posted it like that for quickness. If you need me to I can post the actual code, it is mixed in with a bunch of html table tags and such.

Timotheos

5:11 pm on Mar 19, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi judson,

Thanks for being careful about posting code. I think the only way to get to the bottom of your problem is for you to show us the relevant parts of your php. Here's the guide for posting code.
[webmasterworld.com...]

Tim

judson

5:28 pm on Mar 19, 2004 (gmt 0)

10+ Year Member




<?
$_POST['bg_color'] = &$background;
$_POST['border'] = &$bordercolor;
?>
<? if ($_POST['border'] == "none") :?>
bordercolor="<?=$background?>"><tr>
<td valign="middle" height="100%">
<? else :?>bordercolor="<? echo $bordercolor;?>">

Any suggestions?

Timotheos

11:28 pm on Mar 19, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



<?
$_POST['bg_color'] = &$background;
$_POST['border'] = &$bordercolor;
?>

I'm confused by what you're trying to do here with assigning the POST variables by reference to these other variables.

Can we back up and figure out why your first idea didn't work?


$background = $_POST['bg_color'];
if ($_POST['border'] == "none") {
$bordercolor = $background;
}
else {
$bodercolor = $_POST['border'];
}

Now when it comes to the html later on you can just use
bordercolor="<?=$bordercolor;?>"

I hope that's in line with what you're trying to do.

judson

2:49 pm on Mar 22, 2004 (gmt 0)

10+ Year Member



The variables $background and $bordercolor don't have values before this page. I was under the impression that you could not pass a variable value twice, i.e. once the variable $_POST['bg_color] is used to declare the value of the background color, I could not use it to declare the value of the border color(when the user chooses no border). I may be wrong, I may have had the code wrong, but the border color's value always came back empty.

ergophobe

6:36 pm on Mar 22, 2004 (gmt 0)

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



Judson,

The $_POST array variables persist as long as the script is running. It's true that if you click a link or redirect, you may lose them, but certaintly I can say

$color1 = $_POST['color'];
$color2 = $_POST['color'];
$color3 = $_POST['color'];

All day long. Or actually, for any amount of time up to server timeout, which is less than all day.

Timotheos is right. Let's look at your original script again, since it should work without passing by reference.

One thought. What level of error reporting do you have in your php.ini?

Try it with E_ALL. That will flag any undefined variables and array indices. I'm betting on a typo?

Tom

judson

7:48 pm on Mar 22, 2004 (gmt 0)

10+ Year Member



Error handling is set to E_ALL. I think it may be a typo, but I am not getting an error message just blank input. I noticed before a post had the syntax like this:

<?=$_POST['color3'];?>

But mine uses:

<?=$_POST['color3']?>

This may be the problem. B.T.W. - This is php within HTML, so keep that in mind.