Jump to content

Can only update records once?


acefirefighter

Recommended Posts

I am really not sure if this is a problem with me (probably is), php or mysql.

 

I have a calendar that I am adding events to. If I want to edit only the date I can but only once after I make this update I am out. If I attempt to update the time or event title the database is never updated and I am no longer able to update the date.

here is the controller for the save.

<?php 
function eventsave() {
	$details = $_POST;
	$this->load->model('eventsmodel');

	$this->eventsmodel->eventsave($details,'', TRUE);

	redirect('/admin/events', 'location');

}
?>

I have turned off the redirect to see if I was getting any errors and they seem to be non existent.

 

Here is the model that is used to create a new entry and update a record.

<?php
function eventsave($event) {

		$startdate = explode('-', $event['startdate']);

		$start = mktime($event['starthour'], $event['startmin'], 0, $startdate['0'], $startdate['1'], $startdate['2']);
		$end = mktime($event['endhour'], $event['endmin'], 0, $startdate['0'], $startdate['1'], $startdate['2']);
		$name = $event['name'];


		if (isset($event['id'])) { // if is true then this is an update not a new event
			$data = array(
				'name' => $name,
              	 	'start' => $start,
              	 	'end' => $end
                        );
			$this->db->where('id', $id);
			$this->db->update('events', $data); 
		}else{
			$this->db->set('name', $name);
			$this->db->set('start', $start);
			$this->db->set('end', $end);
			$this->db->insert('events');
		}

}
?>

 

 

I am using code igniter if that helps and the information being submitted by the form looks good.

 

This is the submitted update array and the new event array is just missing the "id"

Array
(
    [name] => test
    [startdate] => 05-14-2011
    [starthour] => 1
    [startmin] => 0
    [endhour] => 1
    [endmin] => 0
    [id] => 54
    [saveevent] => save
)

 

Any suggestions would be appreciated. Thank you.

 

Link to comment
Share on other sites

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.