Forums: [SOLVED] Event to check if date value exists before add - Forums

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

[SOLVED] Event to check if date value exists before add Rate Topic: -----

#1 User is offline   woodey2002 

  • Advanced Member
  • PipPipPip
  • Group: Members
  • Posts: 52
  • Joined: 02-August 09

Posted 15 November 2017 - 02:22 AM

Hi Guys,

On an add page, I'm trying to create a before record added event that will check if the date a of record (chosen by the user) exists in another record.

If it does exist, return a message confirming this and stop the record being saved until the user selects another date.

I found this cool example here

https://xlinesoft.co...cord_exists.htm

I added this code to my before record added event.

//**********  Check if specific record exists  ************
$strSQLExists = "select * from dailydate where date='" . $values["date"] . "'";
$rsExists = db_query($strSQLExists);
$data=db_fetch_array($rsExists);
if($data)
{
// if record exists do something
$message = "date" . $values["date"] . " already exists."
return false;
}
else
{
// if dont exist do something else
}


Anyone got any ideas why refuses to compile? Is "date" a reserved word.

I very much appreciate your thoughts.

Best wishes,
J
0

#2 User is offline   romaldus 

  • Advanced Member
  • PipPipPip
  • Group: Members
  • Posts: 449
  • Joined: 19-May 08

Posted 15 November 2017 - 02:38 AM

Why don't you use "prevent duplicate values" option in visual editor?

https://xlinesoft.co...s__settings.htm
Freelance Programmer | Photographer
0

#3 User is offline   woodey2002 

  • Advanced Member
  • PipPipPip
  • Group: Members
  • Posts: 52
  • Joined: 02-August 09

Posted 15 November 2017 - 07:23 AM

Great Romaldus, that worked perfect.

Many thanks!
0

#4 User is offline   woodey2002 

  • Advanced Member
  • PipPipPip
  • Group: Members
  • Posts: 52
  • Joined: 02-August 09

Posted 16 November 2017 - 01:25 AM

Sorry Guys

I have just noticed that this solution works perfect except my project security settings throw a spanner in the works.

I have my table set for users to see and edit their own data only.

I user A adds a date to the the date field lets say the 15/01/2018 the database should allow that date to be saved as the security settings are set to users to see and edit their own data only.

A problem arises if user B who is part of a separate security group attempts to add 15/01/2018. The application won't allow User B to add the same value as user A, Even though they both users are in separate groups.

Therefore I am wondering if anyone has got any ideas how I can solve this problem I would very much appreciate it.

Many thanks
J
0

#5 User is offline   romaldus 

  • Advanced Member
  • PipPipPip
  • Group: Members
  • Posts: 449
  • Joined: 19-May 08

Posted 16 November 2017 - 02:03 PM

Of course it is easy to check this using before record added event but there is also an easier way. In your table, make sure date field is not a primary key. Than, create unique index contains username and date field.

https://www.sitepoin...ysql-databases/
Freelance Programmer | Photographer
0

#6 User is offline   woodey2002 

  • Advanced Member
  • PipPipPip
  • Group: Members
  • Posts: 52
  • Joined: 02-August 09

Posted 17 November 2017 - 08:16 AM

Many thanks once again Romaldus!

I'm giving that a go now.

Cheers,
J
0

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic