/    Sign up×
Community /Pin to ProfileBookmark

Best way to create variables from selects.

Hi,

Anyone who could help with this would be greatly appreciated.

I have a group of drop down select blocks with options in them. 5 blocks in total with say 5 options within each. All contained within a form.

The select blocks are all representing pages in a web site.

So the first block is anything associated with the home page.
The second being a portfolio.
The third being services
and so on…

Within the same html page the user will be able to add text to go into the page they have selected from the drop downs mentioned above.

In order to do this i need to pick up the selection with REQUEST and use it in a function.

Surely the best way is not using alot of issets?

[code=php]

$home=$_REQUEST[‘home’];
$about=$_REQUEST[‘about’];
$services=$_REQUEST[‘services’];
$portfolio=$_REQUEST[‘portfolio’];
$contact=$_REQUEST[‘contact’];

if(isset($_REQUEST[‘home’]))
if(isset($_REQUEST[‘about’]))
if(isset($_REQUEST[‘services’]))
if(isset($_REQUEST[‘portfolio’]))
if(isset($_REQUEST[‘contact’]))

[/code]

Then carry out the function on whatever one is set?

I’m new to this as you can probs tell.

Any ideas on the best way to do this?

Thanks

a.g.r.c

to post a comment
PHP

5 Comments(s)

Copy linkTweet thisAlerts:
@a_g_r_cauthorJan 26.2008 — Been chatting to a few people....

Would this work?

[code=php]

function submitbodytext () {

if(isset($_REQUEST['blockone, blocktwo, blockthree, blockfour, blockfive'])) {
$blockone=$_REQUEST['blockone'];
$blocktwo=$_REQUEST['blocktwo'];
$blockthree=$_REQUEST['blockthree'];
$blockfour=$_REQUEST['blockfour'];
$blockfive=$_REQUEST['blockfive'];
$contentbody=$_REQUEST['contentbody'];
$sql="INSERT INTO body SET
contentbody='$contentbody'
where pageid='$blockone, $blocktwo, $blockthree, $blockfour, $blockfive'";
if(@mysql_query($sql)) {
echo '<p>Content submitted succesfully</p>';
}
else {
echo '<p>Error submitting content'.mysql_error().'</p>';
}
}
}

[/code]
Copy linkTweet thisAlerts:
@smoseleyJan 26.2008 — WHERE pageid IN ($blockone, $blocktwo, $blockthree, $blockfour, $blockfive);
Copy linkTweet thisAlerts:
@a_g_r_cauthorJan 26.2008 — Thanks,

I might try this, however i'm thinking about changing the page selection menu to be inclusive of all pages. Hover over a category and then the relevant pages come out.

This way the function will only need to capture one variable.

Cheers

a.g.r.c
Copy linkTweet thisAlerts:
@smoseleyJan 26.2008 — But why would you want to insert the same content for 5 pages?

And by the way, you can't have a WHERE clause on an INSERT statement unless it's an INSERT...SELECT
Copy linkTweet thisAlerts:
@a_g_r_cauthorJan 26.2008 — Hey....

Well thats the problem, i would have to expect the user to be responsible with the form and select only one page.. other wise same post for 5 pages.

If i knew jscript i would do some validation to validate only one page selection.

Im pretty sure you can use a where statement when using insert.

Thanks for posting dude.
×

Success!

Help @a_g_r_c 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.5,
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: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...