This topic is locked

Check if exist on edit page

8/8/2010 1:20:35 AM
PHPRunner General questions
J
jccl2 author

Hello,
I tried put action event on edit page for check if register exist before update, but when I put the action on before edit, they back with register exist. I need the solution to check only if the field was updated not the others.
Ex:
Tabel with name and password
John / 1234

Doe / 1234
I put the action event before update to check if the name exist, if the password field was changed they return records already exist, if changed the name to other non existed name like Rambo they return the record already exist.
Where I need to put the information to check if the register already exist before update ?
On add page the event works great, but on edit can´t made work. I tried put the action on before record and after record updated pages.
Thanks.

A
ann 8/9/2010

Hi,
use Before record updated event on the Eventstab. Old values are in the $oldvalues array, new values are in the $values array.

Here is just a sample:

if (($values["Name"])&&($values["PasswordField"]!=$oldvalues["PasswordField"])){

$message="Record exists";

}



where Name, PassowordField are your actual field names.

J
jccl2 author 8/9/2010

Thanks for code but....... still with problem... the code I tried to use:
//** Check if specific record exists ****

global $conn;

$strSQLExists = "select * from test where user='$values[user]'";

$rsExists = db_query($strSQLExists,$conn);

$data=db_fetch_array($rsExists);

if($data)

{

// if record exists do something

$message="Record exists.";

return false;

}

else

{

// if dont exist do something else

}
return true;

//** Check if specific record exists ****
Tried to put

$strSQLExists = "select from test where user='!=$oldvalues[user]'";
or
$strSQLExists = "select
from test where user='!=$values[user]'";
they don´t give error, but don´t check either.
Thanks.

A
ann 8/10/2010

Hi,
you use wrong PHP syntax for concatenation.

Here is the correct one:

$strSQLExists = "select * from test where user='".$values["user"]."'";



Also field names should be quoted.

J
jccl2 author 8/10/2010

Changed to correct syntax, but still with error "Record exists". Only on update, on add works ok.
Thanks.

A
ann 8/11/2010

Hi,
make sure you've setup key column for the table.

Proceed to the Choose pages tab, click Edit button and make sure that there at least one checkbox is checked.

J
jccl2 author 8/11/2010

Checked:

Edit Record

inline edit
I can edit but when save the modification they back with "Record Exist."
Thanks.