/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] concatenated variables increasing in value?

I’m trying to make it so that the form inputs someone submits repopulates if the submitter returns to the form. Easy for text fields, but I’m having a problem with select dropdowns.
Here’s what I have:

[code=php]
<?php
$sel2_sel1 = ‘selected=”selected”‘;
if ($_SESSION[‘frm_start_h’] != “”) {
$opt1 = “sel2_sel” . $_SESSION[‘frm_start_h’];
$$opt1 = ‘ selected=”selected’;
}
?>
<select name=”frm_start_h” id=”frm_start_h”>
<option value=”1″<?=$sel2_sel1?>>1</option>
<option value=”2″<?=$sel2_sel2?>>2</option>
<option value=”3″<?=$sel2_sel3?>>3</option>
<option value=”4″<?=$sel2_sel4?>>4</option>
<option value=”5″<?=$sel2_sel5?>>5</option>
<option value=”6″<?=$sel2_sel6?>>6</option>
<option value=”7″<?=$sel2_sel7?>>7</option>
<option value=”8″<?=$sel2_sel8?>>8</option>
<option value=”9″<?=$sel2_sel9?>>9</option>
<option value=”10″<?=$sel2_sel10?>>10</option>
<option value=”11″<?=$sel2_sel11?>>11</option>
<option value=”12″<?=$sel2_sel12?>>12</option>
</select>
[/code]

But the weird thing is, if someone selects, say, “8” and submits, when they return to the form the “9” will be selected!
No matter what, the item below (in position, or above in value) the one actually selected will be the one that gets re-selected.

The scripting looks fine to me; what am I missing?
Thanks for any feedback!
Liam

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@mechphistoauthorJan 19.2011 — There's a missing " in the $$opt1 = ' selected="selected';

Sheesh!
×

Success!

Help @mechphisto 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.18,
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,
)...