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
https://forums.phpfreaks.com/topic/237839-can-only-update-records-once/
Share on other sites

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.