Jump to content

Deleting rows in a database


Schlo_50

Recommended Posts

I have been making a calendar and can at the moment add new events to each month storing them in a mySQL database. Now i want to add a link next to each month ( e.g April (click to remove events) which when clicked deletes the events associated with that month. I have three rows, id, month and message.

 

Can someone help please?

Thanks!

Link to comment
https://forums.phpfreaks.com/topic/48587-deleting-rows-in-a-database/
Share on other sites

if you're using a link, you have to send the variables via the URL i.e.

 

some_script.php?action=delete&month=MONTH_ID

 

if(isset($_GET['action']){
  $action = $_GET[action];
}
if(isset($_GET['action']){
  $month= $_GET['month'];
}else{
  $month = bad;
}

if($action == "delete"){
  if(is_numeric($month){
    // delete sql query goes here
  }else{
    echo "No month supplied!";
  }
// redirect here, you dont want users to stay on the same page when you pass URL vars that affect the database
}

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.