montymoose
Posts: 85
|
| Posted: 01/13/2008, 2:43 PM |
|
I have a database (mysql php 4) which stores hyperlinks for a website. I want to prevent a user adding an url which is already in the database.
Easy I thought! simply tell codecharge to set the field to 'unique' then change the translations in settings so that the error message says something slightly more friendly. It works great when you INSERT a record, prompting only if the URL is the same as the URL of an existing record. However when you try and UPDATE any record is brings up the unique feild warning, making it unable to UPDATE any records...?
Sorry to post two questions right after each other. Just had a full codecharge day today.
Any suggestions welcomed.
Thanks,
M00S3
|
 |
 |
ckroon
Posts: 869
|
| Posted: 01/13/2008, 5:23 PM |
|
My first guess would be that there are two similar field names in the database already. When it is updating it is scanning them all and throwing the error.
I would export the database into Excel and then Filter->Advanced Filter->Unique Records Only that column to see which records are the culprit.. but I am sure there is an easier way :)
_________________
Walter Kempees...you are dearly missed. |
 |
 |
montymoose
Posts: 85
|
| Posted: 01/14/2008, 2:32 AM |
|
I've sort of fixed it, but it's not a clean fix. I've set the actual mysql database field to accept only unique values. The codecharge unique value property item doesn't seem to work properly. The only problem is, you end up with an ugly sql error when you try to input a duplicate record.
M00s3
|
 |
 |
datadoit
|
| Posted: 01/14/2008, 5:50 AM |
|
Sounds like your form doesn't know what the PK field is.
|
|
|
 |
montymoose
Posts: 85
|
| Posted: 01/14/2008, 5:59 AM |
|
Ahh - maybe... how would I tell it?! you mean by adding a label with the id field showing?
|
 |
 |
datadoit
|
| Posted: 01/14/2008, 6:02 AM |
|
montymoose wrote:
> Ahh - maybe... how would I tell it?! you mean by adding a label with the id
> field showing?
> ---------------------------------------
or add a hidden field for the PK.
|
|
|
 |
montymoose
Posts: 85
|
| Posted: 01/14/2008, 6:12 AM |
|
I've done that and it still doesn't work. Do I have to tell the form it's the PK somewhere?
|
 |
 |
datadoit
|
| Posted: 01/14/2008, 6:19 AM |
|
I would suggest rebuilding the form using the builder, then making
certain that the correct PK field is selected.
Create a second form on the page (don't delete your first one) just to
see if this is indeed the issue.
|
|
|
 |
aondecker
Posts: 58
|
| Posted: 01/14/2008, 7:09 AM |
|
Or you could just write custom code to see if it is unique or not.
something like in your Before Update Event...
$DB1 = new clsdbDATABASE_NAME;
$SQL1 = "select hyperlink from table_name where hyperlink = '".$Form->Hyperlink_Field->GetValue()."'";
$DB1->query($SQL1);
$RS1 = $DB1->next_record();
if ($RS1)
$Form->AddError("Value already in Database.")
That should take care of any problems with uniqueness.
|
 |
 |