This topic is locked

before add

9/13/2007 5:06:44 PM
PHPRunner General questions
A
alex82 author

hi,

i'm using this code:

// Parameters:

// $values - Array object.

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

global $conn;

$pass_var = $values["Password"];

$strSQLExists = "select * from `_Users` where ((Password=".$pass_var."))";

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

$data=db_fetch_array($rsExists);

if($data)

{

// if record exists do something

echo "Change Password";

}

else

{

// if dont exist do something else

}
return true;
// return true if you like to proceed with adding new record

// return false in other case
if the password exists we can see the text but the record is added too,

what i have to do to don´t add the record to the table if the password exists

thanks a lot

L
larsonsc 9/13/2007

I think you just have to add
return false;
after the echo "Change password"; line.
Hope that helps.

A
alex82 author 9/14/2007

hi,

thanks for your help i realize what i forgot i don´t have any programming experience,

i have this code now:

i'm trying to check if a password exits, field Password from table _Users

global $conn;

$pass_var = $values["Password"];

$strSQLExists = "select `Password` from `_Users` where ((Password=".$pass_var."))";

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

$data=db_fetch_array($rsExists);

if($data)

{

// if record exists do something

echo "Hola Mundo";

return false;

}

else

{

// if dont exist do something else

return true;

}
i have this error:

PHP error happened
Technical information

Error type 256

Error description Unknown column 'gyhghg' in 'where clause'

(column 'gyhghg' is the password i'm trying to add)

URL www.mydomain.com/code/_Users_add.php?

Error file /var/www/vhosts/mercasystemplus.com/httpdocs/code/include/dbconnection.php

Error line 26

SQL query insert into `_Users`
what i have to modify?

thanks a lot

Alexey admin 9/14/2007

Alex,
character values must be enclosed in quotes:

$strSQLExists = "select `Password` from `_Users` where ((Password='".$pass_var."'))";