i can get the form´s select bar into a working array so i can delete it in the database?

I am trying to use php to make a simple option list for a form that can save the list in a database, the list are editable so you can add, rename or delete rows in it. I got the rename and the add to work from simple input boxes but i want to use a drop down list for the deletion sounds simple but i don´t manage to understand why it wont work so i will try to ask for help :)

This bit of code is suppose to delete the selected item from the database

<?php
$ukat_to_delete ="";

if (isset($_POST['delunderkat'])) {
    $ukat_to_delete = $_GET['delunderkat'];
    $sql = mysql_query("DELETE FROM listor WHERE underkategori = '$ukat_to_delete' LIMIT 1") or die (mysql_error());
    header("location: lagtillsaker.php");
    exit();
}
?>

and this is the code i use to make a form that shows the list

<form action="lagtillsaker.php" enctype="multipart/form-data" name="myForm3" id="myForm3" method="post">
    <table width="100%" border="0">
        <tr>
            <td width="25%">Ta bort en Underkategori </td>
            <td width="75%"><select name="delunderkat">
                <option value=""></option>
                <?php echo $grupplista ?>
                </select>
                <input name="delunderkatknap" type="submit" value="Ta bort Underkategorin" /></td>
        </tr>
    </table>
</form>

and i use this bit of code to generate the list

<?php

$grupplista="";

$sql=mysql_query("SELECT DISTINCT underkategori FROM listor");
$producktCont=mysql_num_rows($sql);
if ($producktCont>0){
    while($row = mysql_fetch_array($sql)){
        $underkategori = $row["underkategori"];

        $grupplista .= "<option value='$underkategori'>$underkategori</option>";
    }
}else{
    echo "det finns inga underkategorier";

}
?>

i don´t know how i can get the form´s select bar into a working array so i can delete it in the database? I get the code to remove a string or option with no content as if the option value always is nothing in the string output.

Answers


You are doing POST and trying to get the data as GET

$ukat_to_delete = $_GET['delunderkat'];

should be

$ukat_to_delete = $_POST['delunderkat'];

Need Your Help

ibatis dynamic select statement with two dynamic prepend="WHERE"

sql-server ibatis

Hello I would like to do a A complex dynamic select statement with two dynamic prepend="WHERE"

Floating action button morph

android floating-action-button

I want to make this, but I didn't find any tuts or anything how to make it. (It's called Morph on google website) Can anybody tell me how or send some reference pls?