cannot save php code

However when i edit the record, it does not insert into the table that i need.




// Get a db connection.
$db = JFactory::getDbo();

// Create a new query object.
$query = $db->getQuery(true);

// Insert columns.
$columns = array('catid', 'sid', 'original_id', 'state', 'title', 'start_date', 'end_date');

// Insert values.
//$values = array(15,0,0,1,{etempah___purpose},{etempah___start_date},{etempah___end_date});
$values = array('15','0','0','1','kursus','2015-03-07','2015-03-07');

// Prepare the insert query.
$query
->insert($db->quoteName('s8ac1_dpcalendar_events'))
->columns($db->quoteName($columns))
->values(implode(',', $db->quote($values)));

// Reset the query using our newly populated query object.
$db->setQuery($query);

try {
// Execute the query
$result = $db->execute();
//use $db->query() in Joomla2.5
}
catch (Exception $e) {
// catch any database errors.
 
Before executing the query, dump it out and make sure it looks OK.

Code:
var_dump((string)$query);exit;

-- hugh
 
i manage to insert already.

but before i want to insert i want to check if row exist.

my query is
$query
->select( array('alias') )
->from($db->quoteName('s8ac1_dpcalendar_events'))
->where('alias = ' . $db->quote({etempah___id}));

but when i save it give error :

Not Acceptable

An appropriate representation of the requested resource /acacia/administrator/index.php could not be found on this server.
Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.



 
I see your emails, but remember it was 4:30am for me when you sent that, it's 6:30m now ... I'll respond in a while when I've drunk some coffee and woken up.

-- hugh
 
You may have to fetch the etempah___id yourself rather than using a placeholder, like ...

Code:
$etempah_id = $formModel->getElementData('etempah___id', true);
$etempah_id = is_array($etempah_id) ? $etempah_id[0] : $etempah_id;

... and then use $etempah_id instead of the placeholder in your query;

-- hugh
 
You are missing a close paren at the end of that line. You need to close both the quote() and the where() it is in.

Code:
->where('alias = ' . $db->quote($etempah_id));

-- hugh
 
If you use something line Notepad++ to write this stuff in, which has some basic "knowledge" of PHP, it should should show you basic syntax errors. Then you can copy and paste the code to where you need it.

-- hugh
 
$query
->select( array('alias') )
->from($db->quoteName('s8ac1_dpcalendar_events'))
->where('alias = ' . $db->quote($etempah_id));


not working. even with extra paren
 
Cool. I usually recommend using PHP files, and accessing data through the form model (rather than placeholders) for anything other than really simple stuff.

-- hugh
 
Back
Top