Jump to content

Recommended Posts

I have a form that I can type in a name and it displays the name in a list. Below that I have a drop down list that is populated with the same names. What I need is that when you select a name in the drop down list and press the button, it will remove the name from the list. As is right now, I don't get any errrors, but when the page refreshes, the name is still there. Here is what I tried

 

if(isset($_POST['go']))
{
$remove = $_POST['drop_name'];
$sqlRemove ="DELETE FROM mytable(names) VALUES('$remove')";
}

 

and the drop down list

 

<form method="post">
<select name="drop_name">
<?php foreach ($name as $n): ?>
<option><?php echo $n ?></option>
<?php endforeach; ?>
</select>
<input type="submit" name="go" value="remove name"  />
</form>

 

my database name is data, table name is mytable and there is two fields.. id, names

This is the DELETE query syntax prototype -

DELETE [LOW_PRIORITY] [QUICK] [iGNORE] FROM tbl_name

    [WHERE where_condition]

    [ORDER BY ...]

    [LIMIT row_count]

 

As it applies to what you are doing (removing the unused elements) -

 

DELETE FROM tbl_name

    WHERE where_condition

 

@PFMaBiSmAd 

I know answers can be found by reading documentation. I also know that you can write a book on how to read the documentation. I also know that if everyone went to the documentation, there would be no need for this forum. I was going through the documentation. Notice that I did't ask you how to do it, I asked help with code I have been trying

 

@lemmin

 

I tried the code you posted two seconds before receiving your reply, I get the same problem, the page blinks and nothing is removed.

I do have more than one name in the names column. it is a first and last name. But I did not make two colums for the names. I did add the error code like this but get nothing

 

$remove = $_POST['drop_name'];
DELETE FROM mytable WHERE names = '$remove';
error_reporting(E_ALL);

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.