Forums

Problem with save records, and edit it ...

radha_815 29 Jun, 2012
Hello,

I have 2 problem, i made the form and the save the datas in a table in the db, but
when i try to change the primary key, does not save the datas in the table.
For example is i want register many people and i dont want that the id repeat ( but
the id is give it buy the user) so i need that be unique and the form validate when the people in
a field that already is in the table.

how i could not advance in that ... i trying even if the id field is repeat, to modify a data
but i check the tutorial i try so many ways but wont work. the main point is that be able to display all the datas and be able to edit them. like the multi record load pdf, said... but it does work, not even for one data.

im using joomla 2.5 and CF V 4...
if somebody can help please😟
GreyHead 01 Jul, 2012
Hi radha_815,

I'm sorry I don't understand your question here.

You should not even think of letting your users set primary keys for a database table. Use the auto-increment ability of MySQL to create the primary key and save any user generated data in other columns.

Bob
radha_815 02 Jul, 2012
Hi, thanks for reply, yes i understand that, but the thing is that
every user or profile, have their own ID given by the company, so
the main problem that I have if they insert for mistake the same ID, the form would be able
to not record a duplicated data of the id...
maybe is not necessary that this be the PK, but i have to find a way to validated that they not
repeat...
GreyHead 02 Jul, 2012
Hi radha_815,

Then as part of your Serverside validation you can add a check to see if the id is already recorded.
<?php
$db =& JFactory::getDBO();
$query = "
    SELECT COUNT(*)
        FROM `#__some_table`
        WHERE `some_id` = '{$form->data['some_input']}' ;
";
$db->setQuery($query);
$count = $db->loadResult();
if ( $count > 0 ) {
  $form->validation_errors['some_input'] = "This ID is already recorded";
  return false;
}
?>

Bob
This topic is locked and no more replies can be posted.