Jump to content

Option box to change variable


Mistake

Recommended Posts

Hello, i need help by making a script!

 

I need to write a file with option box, so a dropdown menu with 10 or more options, and when i select one option a button to save this option to a php variable in one file! So then i can call up this variable in another file!

 

Please help me! Thank you!

Link to comment
Share on other sites

This should work I think:

 

<?php
session_start();
echo '<form action = "" method = "POST"';
echo'<select name="dropdown">
<option value="store" >Option 1</option>
<option value="values" >Option 2</option>
<option value="here" >Option 3</option>
</select>';
echo '<input type = "submit" name = "submit" value = "Get Value!"
</form>';
if(isset($_POST['submit']))
{

$value = $_POST['dropdown'];

$_SESSION['value'] = $value;

echo $_SESSION['value'];
}




?>

 

To value is stored in $_SESSION['value'] to call the value in another page remember to use session_start(); at the very top.

 

-Glen

Link to comment
Share on other sites

Thank you for your exaple I tried to make what i need with your example! But i could not get what i will!

 

I have a file on my website wich shows the current dj on radio, listeners etc.

 

You can visit it on this adress http://choko-radio.com/eter/radio_stats.php

 

You will se the section DJ Online, I change the name of the dj manually editing the variable in the file!

 

But i need to change the name of the dj trough another file with the options box feature!

 

Please help!

Link to comment
Share on other sites

Thank you for you help, i coded around and i get this to work with this script:

 

<?php
echo '<form action = "" method = "POST"';
echo'<select name="dropdown">
<option value="DJ MisTake" >DJ MisTake</option>
<option value="kenox" >kenox</option>
<option value="TiruRiru" >TiruRiru</option>
</select>';
echo '<input type = "submit" name = "submit" value = "Promjeni DJ-a!"
</form>';
if(isset($_POST['submit']))
{

$value = $_POST['dropdown'];

$string = '<?php 
$djpusta = "'. $_POST['dropdown']. '";
?>';

$fp = fopen("config_dj.php", "w");
fwrite($fp, $string);
fclose($fp);

}

?> 

 

 

Thanks again!

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.