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

Link to comment
Share on other sites

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 .

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.