Jump to content

How to pass php select option value through url


codex

Recommended Posts

I'm trying to pass php select option value to another page through url.but it's not working.please help me.

 

member.php

<?php
mysql_connect("localhost","root","") or die(mysql_error());
mysql_select_db("nordfxlk_member")or die(mysql_error());
$result = mysql_query("SELECT id,ugroup FROM ugroups"); 


?>


<select name='group' id='group' >
<?php 
while ($line = mysql_fetch_array($result)) {
echo '<option value=' . $line['ugroup'] . '>' . $line['ugroup'] . '</option>';


}?>
</select>
<a href="db_sql/add_group.php?ugroup=<?php echo $line['ugroup'] ;?>"> click</a> 

add_group.php

 

 

include('../limoconfig.php');
if(!isset($_SESSION['adminuserid']) )
{
header('Location:../index.php');
}
else
{ 


$ugroup = $_GET['ugroup'];
/*$id = $_GET['id'];*/


$acc_status = "update users set ugroup='".$ugroup."' where id=1931";


echo $acc_status;
$rate = db::getInstance()->exec($acc_status); 


header('Location:../test.php'); 


}
}

 

Values from input fields will only be sent if a form has been submitted.

 

So you need to wrap your <select> field in a form and then submit the form using a button example

<form action="add_group.php" method="get"> <!-- start form -->

<select name='group' id='group' >   <!-- dropdown input field -->
<?php 
while ($line = mysql_fetch_array($result)) {
echo '<option value=' . $line['ugroup'] . '>' . $line['ugroup'] . '</option>';


}?>
</select>
<input type="submit" value="Go" /> <!-- the submit button -->
</form>

Now in add_group.php you'd use $_GET['group'] to retrieve the submitted value.

 

You can do away with submit button and submit the form by applying onchange event handler to select field.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.