Jump to content

Passing values from drop down list to another page


michaelkirby

Recommended Posts

Hi all,

 

I have a drop down reading from a table in the database.

 

When I select the option from the drop down i would require this information to be passed over to another page.

 

Can I use a link? If so is what I am doing correct?

 

Please see the code I'm using below...

 

drop down for category:

 

<p>Select an existing industry:<br />

<select name="categories">

<?php

$selectCategoryQuery = "SELECT * FROM categories ORDER BY categoryname";

$selectCategoryResult = mysql_query($selectCategoryQuery) or die(mysql_error());

 

while($row1Category=mysql_fetch_array($selectCategoryResult))

{ ?>

 

 

<?php echo '<option value="'.$row1Category['categoryid'].'">'.$row1Category['categoryname'].'</option>'; ?>

   

 

<?php }

?>

 

Then I was wondering how to pass the details to another page using a link??

 

<a href="addbrieftocategory.php?categoroyid=<?php echo $row['categoryid']?>" >[+] </a>

 

Which then takes me to another page where I can insert this id into a database table.

 

Can someone please advise me.

 

Thanks in advance

 

 

 

 

Hi,

 

Ok I understand that but maybe I have made a mistake in my code because I can't display the category id or write it to the db.

 

Here is the code I'm using:

 

Form:

 

<form action="addbrieftocategory.php" method="get">

           

                <p>Select a category:<br />

<select name="categories">

<?php

$selectCategoryQuery = "SELECT * FROM categories ORDER BY categoryname";

$selectCategoryResult = mysql_query($selectCategoryQuery) or die(mysql_error());

 

while($row1Category=mysql_fetch_array($selectCategoryResult))

{ ?>

 

 

<?php echo '<option value="'.$row1Category['categoryid'].'">'.$row1Category['categoryname'].'</option>'; ?>

   

 

<?php }

?>

   

</select>

                    <input name="Save" type="submit" value="Upload">

             

                    </form>

 

Then the page the action goes to:

 

<?php

session_start();

require "connect.php";

 

          $briefid = mysql_insert_id($connection);

        $categoryid = $_GET['categoryid'];

     

        echo $categoryid;

 

 

      $query = "insert into briefcat values ('".$briefid."','".$categoryid."') ";

      $result = @mysql_query($query, $connection)or die ("Unable to perform query<br>$query");

 

        //header("Location: briefsassignedto.php");

//exit();

        ?>

 

Is this correct?

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.