This topic is locked
[SOLVED]

 Prevent duplicate values

9/28/2016 5:18:42 PM
PHPRunner General questions
J
jrbr author

How do I get around the empty field with Prevent Duplicate Values?
Lookup Wizard "Please select" message error "Field should not contain a duplicate value"
Thanks

romaldus 9/28/2016



How do I get around the empty field with Prevent Duplicate Values?
Lookup Wizard "Please select" message error "Field should not contain a duplicate value"
Thanks


In phprunner lookup, click create new query button to get rid of / ignore empty fields. For example in mysql:

SELECT product FROM products_table WHERE product_id <> ''


Or to make sure that query returns unique values, use select distinct

SELECT DISTINCT product FROM products_table
J
jrbr author 9/29/2016



In phprunner lookup, click create new query button to get rid of / ignore empty fields. For example in mysql:

SELECT product FROM products_table WHERE product_id <> ''


Or to make sure that query returns unique values, use select distinct

SELECT DISTINCT product FROM products_table



My problem

My link

romaldus 9/29/2016

If you want to PREVENT duplicate values but ALLOW duplicate empty strings ,

  1. In your database make sure CAR field is not set to UNIQUE
  2. In PHPRunner Lookup Wizard, DO NOT check the "Prevent Duplicate Value" option
  3. In PHPRunner, use the following code in Add Page "Before Record Added" and Edit page " Before Record Updated" event:



global $conn;

$sql = "SELECT * FROM cars_table WHERE car ='".$values["car"]."' AND car <> '' ";

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

$data=db_fetch_array($rsExists);
if($data)

{

$message = "Car ".$values["car"]." already exists in database.";

return false;

}


Please read this phprunner manual:

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

J
jrbr author 9/30/2016



If you want to PREVENT duplicate values but ALLOW duplicate empty strings ,

  1. In your database make sure CAR field is not set to UNIQUE
  2. In PHPRunner Lookup Wizard, DO NOT check the "Prevent Duplicate Value" option
  3. In PHPRunner, use the following code in Add Page "Before Record Added" and Edit page " Before Record Updated" event:



global $conn;

$sql = "SELECT * FROM cars_table WHERE car ='".$values["car"]."' AND car <> '' ";

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

$data=db_fetch_array($rsExists);
if($data)

{

$message = "Car ".$values["car"]." already exists in database.";

return false;

}


Please read this phprunner manual:

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


Perfect. Thank you very much.