hello, this alternative method was my solution to a simple trouble, the main idea is validate if the key exists in table "personas", the main trouble is "personas" has not a unique key, the main key rut is shared with other users, so the code of sql is
CREATE TABLE persona
(
ID
INT(11) NOT NULL AUTO_INCREMENT,
usuario_ID
INT(11) NOT NULL,
empresa_ID
INT(11) NOT NULL,
rut
VARCHAR(10) NOT NULL,
nombres
VARCHAR(50) NOT NULL,
PRIMARY KEY (ID
));
if you can see, the rut field isn't unique for the all table, so the option "prevent duplicate" in the field definition doesn't work.
my solution was use the custom validation javascript (that can be put in c:\Program Files\PHPRunner8.1\source\include\validate\) and activate in the validate as option) and a second php file
the code is something like this.
javascript code
function validarut(sVal){
VALIDATION CODE IS HERE!!when all is ok with the code perform the aditional php code
$.get("./addon/inforut.php", {prut: sVal, tipo: "persona"}, function(respuesta){
if (respuesta.rut_existe == "SI")
{
alert("El rut ingresado ya existe");
}
}, "json");
inforut.php
<?php require_once("../include/dbcommon.php");
if (VALIDATION ROUTINE OK!!)
{echo json_encode(array("rut_existe"=>"SI"));}
else
{echo json_encode(array("rut_existe"=>"NO"));}}
?>
This work perfectly, but the asyncronous ejecution of java script doesn't allow to use the same text alert to validation. for that i use an alert popup message, is not the most elegant solution, but works.
If any can improve this, i really apreciate.
best regards
Carlos Oschilewski