Jump to content

Recommended Posts

I have a calendar that users can add events to. When a user adds an event, it is displayed under "Today's Events" and the user that added it is saved in the calendar_events table under the user field for that event

 

I'm trying to allow users to delete their events, but I'm not sure exactly what to do...

 

here's the part that I'm having problems with...I know I should create a link to a delete.php file, but how would I call on the id of the event in that link? Also, right now the delete is coming up for every event, not just the ones which the user created

 

if ($_COOKIE['ID_staples_clubs'] = 'user') {
$delete = " ????";}
else {$delete = "";}
$event_txt .= "<li><strong>".$fmt_date."</strong>:
".$event_title."</br>".$event_shortdesc."<br/>".$delete."</li>";
}
$event_txt .= "</ul>";

<html>
<head>
<title>Show/Add Events</title>
</head>
<body>
<h1>Show/Add Events</h1>
<?php
$mysqli = mysqli_connect ------;

//add new event
if ($_POST) {
$m = $_POST["m"];
$d = $_POST["d"];
$y = $_POST["y"];

$event_date = $y."-".$m."-".$d." ".$_POST["event_time_hh"].":".$_POST["event_time_mm"].":00";
$insEvent_sql = "INSERT INTO calendar_events (event_title, event_shortdesc, event_start, user) VALUES ('".$_POST["event_title"]."', '".$_POST["event_shortdesc"]."', '$event_date','".$_COOKIE['ID_staples_clubs']."')";
$insEvent_res = mysqli_query($mysqli, $insEvent_sql) or die(mysqli_error($mysqli));
} else {
$m = $_GET["m"];
$d = $_GET["d"];
$y = $_GET["y"];
}

//show events
$getEvent_sql = "SELECT event_title, event_shortdesc, date_format(event_start, '%I:%i %p') AS fmt_date FROM calendar_events WHERE month(event_start) = '".$m."' AND dayofmonth(event_start) = '".$d."' AND year(event_start) = '".$y."' ORDER BY event_start";
$getEvent_res = mysqli_query($mysqli, $getEvent_sql) or die(mysqli_error($mysqli));

if (mysqli_num_rows($getEvent_res) > 0) {
$event_txt = "<ul>";
while ($ev = mysqli_fetch_array($getEvent_res)) {
$event_title = stripslashes($ev["event_title"]);
$event_shortdesc = stripslashes($ev["event_shortdesc"]);
$fmt_date = $ev["fmt_date"];
if ($_COOKIE['ID_staples_clubs'] = 'user') {
$delete = " ????";}
else {$delete = "";}
$event_txt .= "<li><strong>".$fmt_date."</strong>:
".$event_title."</br>".$event_shortdesc."<br/>".$delete."</li>";
}
$event_txt .= "</ul>";
mysqli_free_result($getEvent_res);
} else {
$event_txt = "";
}

mysqli_close($mysqli);

if ($event_txt != "") {
echo "<p><strong>Today's Events:</strong></p>
$event_txt
<hr/>";
}

if(isset($_COOKIE['ID_staples_clubs']) && isset($_COOKIE['Key_staples_clubs']))
{
//show form
echo "
<form method=\"post\" action=\"".$_SERVER["PHP_SELF"]."\">
<p><strong>Would you like to add an event?</strong><br/>
Complete the form below and press the submit button to add an event</p>
<p><strong>Event Title:</strong><br/>
<input type=\"text\" name=\"event_title\" size=\"25\" maxlength=\"25\" />
<p><strong>Event Description:</strong><br/>
<input type=\"text\" name=\"event_shortdesc\" size=\"25\" maxlength=\"255\" />
<p><strong>Event Time (hh:mm):</strong><br/>

<select name=\"event_time_hh\">
<option value=\"0\">12AM</option>
<option value=\"1\">1AM</option>
<option value=\"2\">2AM</option>
<option value=\"3\">3AM</option>
<option value=\"4\">4AM</option>
<option value=\"5\">5AM</option>
<option value=\"6\">6AM</option>
<option value=\"7\">7AM</option>
<option value=\"8\">8AM</option>
<option value=\"9\">9AM</option>
<option value=\"10\">10PM</option>
<option value=\"11\">11PM</option>
<option value=\"12\">12PM</option>
<option value=\"13\">1PM</option>
<option value=\"14\">2PM</option>
<option value=\"15\">3PM</option>
<option value=\"16\">4PM</option>
<option value=\"17\">5PM</option>
<option value=\"18\">6PM</option>
<option value=\"19\">7PM</option>
<option value=\"20\">8PM</option>
<option value=\"21\">9PM</option>
<option value=\"22\">10PM</option>
<option value=\"23\">11PM</option>
</select> :
<input type=\"text\" name=\"event_time_mm\" size=\"2\" maxlength=\"2\" />

<input type=\"hidden\" name=\"m\" value=\"".$m."\">
<input type=\"hidden\" name=\"d\" value=\"".$d."\">
<input type=\"hidden\" name=\"y\" value=\"".$y."\">
<br/><br/>
<input type=\"submit\" name=\"submit\" value=\"Add Event\">
</form>";
}
?>
</body>
</html>

 

Thanks!

Link to comment
https://forums.phpfreaks.com/topic/186448-user-deleting-calendar-events/
Share on other sites

your are storing in the event the user. You need to match the user value against the current user. If they match you need to build the delete link otherwise you dont.

 

You also need to give each event a unique ID so you can use it into the delete link, either auto-increment or timestamp would do.

 

You might want to think about a combined edit/delete form. Cause you should also allow them to edit their post.

 

HTH

Teamatomic

 

 

Oh, good idea

To match the user, I tried doing:

if ($_COOKIE['ID_staples_clubs'] = 'user') {
$delete = " ????";}
else {$delete = "";}

So if I have the username stored as a cookie, shouldn't ???? come up only if I'm logged in as the user who added the event? Because right now it's coming up no matter what.

Oh, thank you! It's not coming up, though. I don't think I can compare the cookie to 'user', because I want to compare it to the user field in my database, not just the string "user"

 

$getEvent_sql = "SELECT id, event_title, event_shortdesc, user, date_format(event_start, '%I:%i %p') AS fmt_date FROM calendar_events WHERE month(event_start) = '".$m."' AND dayofmonth(event_start) = '".$d."' AND year(event_start) = '".$y."' ORDER BY event_start";
$getEvent_res = mysqli_query($mysqli, $getEvent_sql) or die(mysqli_error($mysqli));

if (mysqli_num_rows($getEvent_res) > 0) {

if ($_COOKIE['ID_staples_clubs'] == 'user') {
$delete = "delete";}
else {$delete = "";}

$event_txt = "<ul>";
while ($ev = mysqli_fetch_array($getEvent_res)) {
$event_title = stripslashes($ev["event_title"]);
$event_shortdesc = stripslashes($ev["event_shortdesc"]);
$id = $ev['id'];
$fmt_date = $ev["fmt_date"];

$event_txt .= "<li><strong>".$fmt_date."</strong>:
".$event_title."</br>".$event_shortdesc."<br/>".$delete."</li>";
}
$event_txt .= "</ul>";
mysqli_free_result($getEvent_res);
} else {
$event_txt = "";
}

would using $SESSION_ be better than $COOKIE_ then?

 

I'm just wondering if I do

if ($_COOKIE['ID_staples_clubs'] == 'user') {
$delete = "delete";}
else {$delete = "";}

isn't the 'user' that I'm comparing to the cookie just the word user? How do I compare it to the user that's stored?

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.