Jump to content

[SOLVED] How to cary a variable from a value


Monk3h

Recommended Posts

I have created a script to bring back some info from my database in the form of a drop down menu. i did this using an array.

 

<option value='$ability[id]'>$ability[name]</option>

 

 

$ability[name] obviously prints the name of each ability into a drop down menu (i have removed to array to make this quicker).

 

the value is the abilitys ID, this is what i want to carry forward.

 

there is a submit button after the drop down menu. what i want to do is once the ability name is selected i would like to be able to print the ability id. how would i do this out of the arrey?

 

Thanks in advance. :)

Link to comment
Share on other sites

Well it should be coming from $_POST right, so we have to know what the ID that is chosen was; obviously dumping the var would work but not if you have other $_POST vars which you most likely do, so your best bet IMO is to compare $_POST to the array again kind of like this.

<?php
if(isset($_POST[$ability[id])) {

?>

Link to comment
Share on other sites

So twice now I have tried to post with out success.

What i meant to say is you need to include name in your option.

<?php 
echo "<option name='ability' value='$ability[id]'>$ability[name]</option>";
?>

then you will be able to echo that option like so.

<?php 
echo $_POST['ability']; //this will contian the assigned value from $ability[id]
//of course do not forget to screen for security.
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.