Hello everyone,
I need a PHP expression to validate a field value against a list predefined in mysql database
So that anything different from that in the database will not be submitted to the database.
This is what i did but was unsuccessful:
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
// Database connection details.
$username = "cardinet_admin01";
$password = "code###";
$database = "cardinet_codelist";
// Connect to the database.
$conn = @mysql_connect('localhost', $username, $password) or die("Unable to connect to MySQL");
@mysql_select_db($database, $conn) or die( "Unable to select database");
$formScratchCode=$_POST['ScratchCode'];
$selectQuery = db_query("SELECT Scode FROM CodeList WHERE Scode='$formScratchCode'");
// see if there are any matches
if (db_numrows($selectQuery) == 1)
// if a match occurs, then allow form submission
return true;
{
else
{
echo 'Your scratch code is not valid. Please insert a valid code.';
}
mysql_close($conn);
}
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Its to be placed inside the CHECK field under FIELDS BUILDER - Advanced settings to define the activities of the field.
In the same window where we enable MANDATORY FIELD setting.
Please I am a baby in php and willing to learn>
Looking forward to your assistance
Cheers.
