Emir Dupovac
Emir Dupovac

Reputation: 756

MySQL and PHP delete row from dropdown

I wish to use dropdown to list all rows from database. When I select one option, delete that selected row with button. Here what I have by now, this only shows dropdown:

$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Nije se moguće konektovati: ' . mysql_error());
}

 mysql_select_db("videoteka", $con);

$result = mysql_query("select ime,id from filmovi");

$options=""; 

echo "Odaberite film:";

 while ($row=mysql_fetch_array($result)) { 

$id=$row["id"]; 
$ime=$row["ime"]; 
$options.="<OPTION VALUE=\"$id\">".$ime.'</option>';
}

mysql_close($con);

And in body:

<select name=thing> 
<option value=0><?=$options?></option>
</select> 

Upvotes: 0

Views: 1604

Answers (1)

Aioros
Aioros

Reputation: 4383

Ok, so two things, just to try and put you in the right direction: first, in the body you can remove the <option> tag, since your php variable already contains those.

<select name=thing> 
<?=$options?>
</select>

Second, the delete part. There are different ways to do this, but one thing you will certainly need is an HTML form. Your select (and the button) will need to be in this form, which will be submitted to this very same PHP page. In the beginning of your PHP code you will check the $_POST variable to determine what row to delete. I hope you know what $_POST is, otherwise this is going to be a pretty useless explanation.

Upvotes: 2

Related Questions