Reputation: 466
i have two forms (formulaire.html) and (authentification.html), the first i used to lo signe up and the second i use to signe up.. and i have one classe php that i develloped my two function for the two forms.. i used $_SERVER in if condition to separate the forms but it does't work , here is my php Class thanj you for help
<?php
include 'Admin.php';
include 'config.php';
class Register
{
public $conn;
function __construct()
{
$c=new config();
$this->conn=$c->connexion();
}
function RegistrerAdmin($admin,$conn)
{
$req="INSERT INTO `utilisateur`
(`nom`, `prenom`, `age`,`login`, `pwd`, `type`)
VALUES('".$admin->recupererNom()."','".$admin->getPrenom()."',
'".$admin->getage()."','".$admin->login."',
'".$admin->pwd."','administrateur')";
$conn->query($req);
}
function sauthentifier($login,$pwd,$conn)
{
$req="select * from utilisateur where login ='".$login."'
AND pwd='".$pwd."'";
$res= $conn->query($req);
$valide=$res->fetchColumn();
if ($valide)
{
echo 'authentification rèussi ';
}
else
echo 'verifier login ou mdp';
}
}
$a= new Register();
$admin=new Admin($_POST['nom'],$_POST['prenom'],$_POST['age'],
$_POST['login'],$_POST['pwd']);
if ($_SERVER['/Formulaire.html'] )
{
if($_POST['pwd']==$_POST['confirm'])
{
$a->RegistrerAdmin($admin,$a->conn);
echo 'bienvenue'.$_POST['nom'];
}
else echo 'mot de passe et confirm incorrecte ';
}
else if ($_SERVER['/authentification.html'] )
{
$a->sauthentifier($_POST['login'],$_POST['pwd'],$a->conn);
}
?>
Upvotes: 0
Views: 46
Reputation: 2817
You should use $_SERVER['PHP_SELF'] == '/Formulaire.html'
or $_SERVER['PHP_SELF'] == '/authentification.html'
to indicate current called php file instead of just calling $_SERVER['/Formulaire.html']
Also I'd recommend you to split actions code into three different files: one will contain your class code and two others - actions to execute on forms submission.
Upvotes: 0
Reputation: 1332
try to echo
echo $_SERVER['REQUEST_URI'];
and check whats in it after submit, then compare
if ($_SERVER['REQUEST_URI'] == 'your_url')
Or you can send something in $_POST
to differentiate both form submission like:
Form1 submit button
<input type="submit" name="reg1_submit" value="Submit">
Form2 submit button
<input type="submit" name="reg2_submit" value="Submit">
PHP code
if (isset($_POST['reg1_submit'])){
if($_POST['pwd']==$_POST['confirm']){
$a->RegistrerAdmin($admin,$a->conn);
echo 'bienvenue'.$_POST['nom'];
}
else
echo 'mot de passe et confirm incorrecte ';
}else if (isset($_POST['reg2_submit'])){
$a->sauthentifier($_POST['login'],$_POST['pwd'],$a->conn);
}
Upvotes: 2