Data insertion mess up in mysql database using php

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
skotidas
Forum Newbie
Posts: 1
Joined: Fri Nov 06, 2009 3:01 am

Data insertion mess up in mysql database using php

Post by skotidas »

Hi i have a question regarding data inserts into mysql using php functions.
I use the joomla cms and trying to create a component.My table has 2 fields
id (primary key,int , auto increment)
link (varchar)
When i try to save a new link in joomla backend using this code

Code: Select all

function saveLink($link)
{
 
$googlemapTableRow =& $this->getTable('googlemap');
 
// Bind the form fields to the googlemap table
if (!$googlemapTableRow->bind($link)) {
JError::raiseError(500, 'Error binding data');
}
 
// Make sure the link record is valid
if (!$googlemapTableRow->check()) {
JError::raiseError(500, 'Invalid data');
}
 
// Insert/update this record in the db
if (!$googlemapTableRow->store()) {
$errorMessage = $googlemapTableRow->getError();
JError::raiseError(500, 'Error binding data: '.$errorMessage);
}
//If we get here and with no raiseErrors, then everythign went well
} 
 

where $link is

Code: Select all

$link = JRequest::get( 'POST'); $link['link']=htmlspecialchars(JRequest::getVar('link',null,'default',string,JREQUEST_ALLOWRAW), ENT_QUOTES, 'UTF-8');
everything works fine. BUT if i delete one or more rows using

Code: Select all

function deleteLinks($arrayIDs)
{
//foreach(ids as $arrayIDs){
$query = 'DELETE FROM #__googlemap WHERE id IN ('.implode(',', $arrayIDs).')';
$db = $this->getDBO();
$db->setQuery($query);
if (!$db->query()){
$errorMessage = $this->getDBO()->getErrorMsg();
JError::raiseError(500, 'Error deleting greetings: '.$errorMessage);
}
}
where $arrayIDs is

Code: Select all

$arrayIDs = JRequest::getVar('cid', array(), 'default', 'array' ); //Reads cid as an array
data is inserted in a weird way .For example my table looks like
id link
4 link4
3 link3
2 link2
1 link1
Its like everytime i use the deleteLinks() the sorting changes from ascending/descending to descending/ascending even though i dont use any sorting.Any ideas?
If u need more info about joomla functions let me know.
Thanks in advance
Post Reply