im using php and mysql
and everything is ok until it drive me crazy and im not able to delete a record from the database
i have a list box using a recordset from the database the display the item in it
so i wrote this code when click on submit
<?php
$modeldel= $_POST['model'];
$result = mysql_query("DELETE FROM car_table where car_ID LIKE '%$modeldel%' ")or die(mysql_error());
?>
it doesnt delete ...what is the right code ...plz help ,,i tried everything
You're not actually running anything to delete it! You just save the query in a variable.
If you were to do just:
[php]
$modeldel= $_POST['model'];
mysql_query("DELETE FROM car_table where car_ID LIKE '%$modeldel%' ")or die(mysql_error());
[/php]
it would work :)
Or to work on the code you wrote, you could put it in an 'if' statement;
[php]
$modeldel= $_POST['model'];
$result = mysql_query("DELETE FROM car_table where car_ID LIKE '%$modeldel%' ")or die(mysql_error());
if(!$result){
// if it isn't successfully deleted; run this code
} else {
// successful delete; run code.
}
[/php]