Jump to content

creating a 'delete' button using form action & data from a drop dialogue box


darkenroyce

Recommended Posts

Hi

 

I want to use an input from a drop dialogue box which displays a list of user records from a column of in a MySQL table.  When the users select the option they wish to delete they need to press the "submit button" labelled 'delete'.  I have coded the drop down dialogue box but I can't the button to delete the record within the MySQL table.  The code for the drop dialogue box is below:

 

<td><select>
    
    <?php

    $conn = mysql_connect("localhost", "root") or die(mysql_error());

    //database selected

    mysql_select_db("database", $conn) or die(mysql_error());
            
    $state = "SELECT name FROM data";
              
    $query = mysql_query($state, $conn);    

    while($queryColumn = mysql_fetch_array($query)){
       echo '<option value="' . $queryColumn ['name'] . '">' . $queryColumn ['name'] . '</option>';
    } 
    
       
    ?>

 

 

I using the

<form action = "filename" METHOD=POST></form>

for this small form.

 

The php file this redirects to runs this php code:

 

<?php
    $con = mysql_connect("localhost","root") or die(mysql_error());
    if (!$con)
    {
    die('Could not connect: ' . mysql_error());
    }

    mysql_select_db("database", $con);
    $sql3 = "DELETE FROM data WHERE name VALUES ('$_POST[delete_data]')" 
    mysql_query($sql3,$con);
    mysql_close($con);
    
?>

 

delete_data refers to

<input type="submit" name="delete_data" value="Delete">

 

Am I along the right tracks or completed wrong. This has been racking my brain for a while...

 

Thanks

Hi

 

I want to use an input from a drop dialogue box which displays a list of user records from a column of in a MySQL table.  When the users select the option they wish to delete they need to press the "submit button" labelled 'delete'.  I have coded the drop down dialogue box but I can't the button to delete the record within the MySQL table.  The code for the drop dialogue box is below:

 

<td><select>
    
    <?php

    $conn = mysql_connect("localhost", "root") or die(mysql_error());

    //database selected

    mysql_select_db("database", $conn) or die(mysql_error());
            
    $state = "SELECT name FROM data";
              
    $query = mysql_query($state, $conn);    

    while($queryColumn = mysql_fetch_array($query)){
       echo '<option value="' . $queryColumn ['name'] . '">' . $queryColumn ['name'] . '</option>';
    } 
    
       
    ?>

 

 

I using the

<form action = "filename" METHOD=POST></form>

for this small form.

 

The php file this redirects to runs this php code:

 

<?php
    $con = mysql_connect("localhost","root") or die(mysql_error());
    if (!$con)
    {
    die('Could not connect: ' . mysql_error());
    }

    mysql_select_db("database", $con);
    $sql3 = "DELETE FROM data WHERE name VALUES ('$_POST[delete_data]')" 
    mysql_query($sql3,$con);
    mysql_close($con);
    
?>

 

delete_data refers to

<input type="submit" name="delete_data" value="Delete">

 

Am I along the right tracks or completed wrong. This has been racking my brain for a while...

 

Thanks

 

The only problem i can see is in the delete query.

 

<?php
    $con = mysql_connect("localhost","root") or die(mysql_error());
    if (!$con)
    {
    die('Could not connect: ' . mysql_error());
    }

    mysql_select_db("database", $con);
    $sql3 = "DELETE FROM data WHERE name = '".$_POST[delete_data]."'" 
    mysql_query($sql3,$con);
    mysql_close($con);
    
?>

 

is what it should be.

 

and also the button should be named submit, and the select drop down menu hould be named delete_data .

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.