This topic is locked

checking if record exists

10/15/2006 6:16:06 AM
PHPRunner General questions
A
alex82 author

hi,

i'm testing table events before record added,

i have a simple table _Langs:

select `lid`,

`lname`

From `_Langs`

lid primary key and i also want lname unique, i added this code at

table events before record added:
function BeforeAdd(&$values)

{
// Parameters:

// $values - Array object.

// Each field on the Add form represented as 'Field name'-'Field value' pair
//** Check if specific record exists ****

global $conn;

$strSQLExists = "select * from _Langs where lname=".$values["lname"];

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

$data=db_fetch_array($rsExists);

if($data)

{

// if record exists do something

return false;

}

else

{

// if dont exist do something else

return true;

}

}
but i have always same error:
PHP error happened
Technical information

Error type 256

Error description Unknown column 'es' in 'where clause' (es is the value i tried to add)

URL _Langs_add.php?

Error file /var/www/vhosts/site/httpdocs/phprunner/include/dbconnection.php

Error line 26

SQL query insert into `_Langs`
what have i to change?

thanks a lot

Alexey admin 10/15/2006

Alex,
you need to add quotes to the character value in SQL string.

Here is the correct line of code for your event:

$strSQLExists = "select * from _Langs where lname='".$values["lname"]."'";