Page 1 of 1
Edit User Event Posted
Posted: Wed Nov 17, 2010 9:14 pm
by brmcdani44
I have an event calendar that users can first register and then post events. I am trying to find a tutorial that will show me how to add edit functionality for the events these users post. Can anyone point me in the right direction of a good tutorial for this? I have queried Google for a while now without any luck?
Thanks in advance!
Re: Edit User Event Posted
Posted: Wed Nov 17, 2010 9:24 pm
by Celauran
I don't have a tutorial to point to, but you could simply retrieve the given event from the DB, use the results to populate a form similar to the one used for the initial submission, the user can make changes within the form, then stick everything back in the database via UPDATE rather than INSERT when the form is submitted.
Re: Edit User Event Posted
Posted: Wed Nov 17, 2010 10:14 pm
by s992
Here's a little sample to give you a headstart on populating the fields with existing data. To handle updating the record, just use UPDATE (like Celauran said).
Code: Select all
<?php
$query = "SELECT * FROM events WHERE id = $id";
$result = mysql_query($query) OR die(mysql_error());
$array = mysql_fetch_assoc($result);
?>
<form method=POST action="some_page.php">
<input type="text" name="title" value="<?php echo $array['title']; ?>" /><br />
<input type="text" name="date" value="<?php echo $array['date']; ?>" /><br />
<textarea name="description"><?php echo $array['description']; ?>"</textarea><br />
<input type="submit" value="Update Event" />
</form>
Re: Edit User Event Posted
Posted: Wed Nov 17, 2010 11:40 pm
by brmcdani44
When you say where id=$id is that what will determine which posting belongs to the user? How do you pull the user id from the session to where you can match it against the event data row?
Re: Edit User Event Posted
Posted: Wed Nov 17, 2010 11:45 pm
by s992
$id in my sample code referred to the ID of whichever event was being modified. You can pass this through $_SESSION or $_GET - however you would prefer. I would probably pass it through $_GET, such as
http://www.mysite.com/edit_event.php?id=123. Of course, you're going to want to verify that the user is logged in and that the event belongs to them before even presenting them with the form.
Re: Edit User Event Posted
Posted: Thu Nov 18, 2010 7:52 am
by Celauran
brmcdani44 wrote:When you say where id=$id is that what will determine which posting belongs to the user? How do you pull the user id from the session to where you can match it against the event data row?
Do you already have something in place whereby the user can view all of his/her events?
Code: Select all
SELECT * FROM events WHERE user = $_SESSION['user']
or something similar.
You can then loop through the results and build a list of events. Each event has a unique id which you can pass to the editing form (via POST, GET, whatever) when they select which event they wish to edit.
Re: Edit User Event Posted
Posted: Thu Nov 18, 2010 8:40 am
by brmcdani44
That makes sense. I already have something in place that pulls the data if the user enters a date for the event. The only problem is it returns all events for that date that are not specific to the user. Thanks to the both of you for your help. I may have more questions as I move forward with this.