jeudi 29 octobre 2015

Dynamically create IF in PHP from database

I store dynamic conditions in Mysql in order to create conditions; I would need to create those conditions in PHP in order to accept if not the form.

Example: Database:

===============================
COND1  |  COND2  |  COND3  |
1      |  4      |         |
       |  4      |  3      |

I would like to make a loop inside BDD a create conditions:

if (($_POST[1]=="1") and ($_POST[2]=="4"){echo "ERROR";}
if ($_POST[2]=="4"){echo "ERROR";}
if (($_POST[2]=="4") and ($_POST[3]=="3"){echo "ERROR";}

Because conditions are dynamics I cannot create the IF statements

Id tried something like that but not working

if ($cond1!=""){$req0=" and (".$_POST['v1']." ==\"$cond1\")";}
if ($conf2!=""){$req1=" and (".$_POST['v2']." ==\"$cond2\")";}
if ($cond3!=""){$req2=" and (".$_POST['v3']." ==\"$cond3\")";}

if ("".$req0." ".$req1." ".$req2.""){//echo "ERREUR";}

I don't know how to generate if conditions in PHP :-(

Aucun commentaire:

Enregistrer un commentaire