2015-09-26 18 views
0

我使用php devlopping一個應用程序,我會在一個頁面php中添加2個按鈕,我將每個bottons的名稱傳遞給函數(POST)像這樣(isset($ _ POST ['action']))但我不能做到這一點,你可以幫我我怎麼可以做許多提交在一個頁面與PHP?

<?php 
 
$host = "localhost"; 
 
\t $user = "root"; 
 
\t $db = "reseau"; 
 
\t $con = @mysql_connect('localhost', 'root', ''); 
 
\t $select = @mysql_select_db ('reseau') ; 
 

 
if (isset($_POST['action'])) { 
 
    \t if(isset($_POST['nom'])) $nom = htmlspecialchars(pg_escape_string($_POST['nom'])); 
 
\t else  $nom=""; 
 
\t if(isset($_POST['prenom'])) $prenom = htmlspecialchars(pg_escape_string($_POST['prenom'])); 
 
\t else  $prenom=""; 
 
\t if(isset($_POST['email'])) $email = $email = htmlspecialchars(pg_escape_string($_POST['email'])); 
 
\t else  $email=""; 
 
\t if(isset($_POST['password'])) $password = htmlspecialchars(pg_escape_string($_POST['password'])); 
 
\t else  $password=""; 
 
\t if(isset($_POST['naissance'])) $naissance = htmlspecialchars(pg_escape_string($_POST['naissance'])); 
 
\t else  $naissance=""; 
 
\t if(isset($_POST['sexe'])) $sexe = htmlspecialchars(pg_escape_string($_POST['sexe'])); 
 
\t else  $sexe=""; 
 
\t $query = "INSERT INTO usager(nom,prenom,email,password,naissance,sexe) VALUES ('" . $nom . "', '" . $prenom . "', '" . $email . "', '" . $password . "', '" . $naissance . "', '" . $sexe . "')"; 
 
    $result = mysql_query($query); 
 
    if (!$result) { 
 
    $errormessage = mysql_error(); 
 
    echo "Error with query: " . $errormessage; 
 
    exit(); 
 
    } 
 
} 
 
else if(isset($_POST['enter'])){ 
 
\t \t if(empty($_POST['nom']) === false && empty($_POST['password']) === false){ 
 
\t \t \t $nom = htmlspecialchars(pg_escape_string(trim($_POST['nom']))); 
 
\t \t \t $password = htmlspecialchars(pg_escape_string(trim($_POST['password']))); 
 
\t \t \t $query = mysql_query("SELECT * FROM usager WHERE nom = '$nom' AND password = '$password'")or die(mysql_error()); 
 
\t \t \t $count = mysql_num_rows($query); 
 
\t \t \t if($count == 0){ 
 
\t \t \t \t $output= "combinaison nom d'utilisateur/mot de passe incorrecte. réessayez"; 
 
\t \t \t }else{ 
 
\t \t \t \t session_start(); 
 
\t \t \t \t $_SESSION['nom']=htmlspecialchars(pg_escape_string(trim($_POST['nom']))); 
 
\t \t \t \t $_SESSION['password']=htmlspecialchars(pg_escape_string(trim($_POST['password']))); 
 
\t \t \t \t header("Location: index1.php"); 
 
\t \t \t } 
 
\t \t }else{ 
 
\t \t \t $output= 'veuillez saisir tout les champs'; 
 
\t \t } 
 
\t } 
 

 
?> 
 
<!DOCemail html> 
 
<html> 
 
<body style="background-image:url(6a00e554acca9b8834014e86765de6970d.jpg); 
 
background-attachment : fixed; 
 
background-position : 50% 50%; 
 
background-size  : cover; 
 
"> 
 
<form name="nl" action="" method="POST"> 
 
    <fieldset style="width: 370px; margin-top: 100px;"> 
 
\t \t <legend style= "left: 120px;">Creer un compte</legend> 
 
\t \t <p><label for="text">Nom</label><input required placeholder="votre nom" title="Ce texte ne doit comprendre que des lettres" id="text" email="text" name="nom" style="height: 31px; margin-left: 25px;"/></p> 
 
\t \t <p><label for="email">Prenom</label><input required placeholder="votre prenom " id="email" type="text" name="prenom"style="height: 31px; margin-left: 25px;" /></p> 
 
\t \t <p><label for="password">Email</label><input required placeholder="votre email " id="url" type="text" name="email" style="height: 31px; margin-left: 25px;"/></p> 
 
\t \t <p><label for="url">Mot de passe</label><input required placeholder="votre mot de passe " id="url"type="password" name="password" style="height: 31px; margin-left: 25px;"/></p> 
 
     <p><label for="url" style="width: 147px;">Date de naissance</label><input required id="birthdate" name="naissance" type="date" style="height: 31px;"/></p> 
 
    <p><label style=" 
 
    width: 90px; 
 
">Sexe</label><a>homme</a> 
 
    <input type="radio" name="sexe" value="male" 
 
\t checked="checked" style=" 
 
    width: 20px; 
 
"/> 
 
    <a>femme</a> 
 
    <input type="radio" value="women" name="sexe" style=" 
 
    width: 20px; 
 
"/></p> 
 
    </fieldset> 
 
    <button type='submit' name='action' class="button" value="action" style=" 
 
\t \t padding-left: 18px; 
 
\t \t padding-right: 18px; 
 
\t \t padding-top: 13px; 
 
\t \t padding-bottom: 13px; 
 
\t \t margin-top: 0px; 
 
\t \t border-top-width: 0px; 
 
\t \t margin-right: 950px; 
 
\t \t ">Inscription</button> 
 
\t \t <div id="main" class="container" style="left: 1150px;top: 270px;"> 
 
\t <fieldset> 
 
\t <legend style=" 
 
    margin-left: 65px; 
 
">Login In</legend> 
 
\t <p class="login-username"> 
 
\t \t <label for="nom">Nom:</label> <input type="text" name="nom" id="user_login" class="input" value="" size="20" 
 
\t \t placeholder="Username" style=" 
 
    height: 36px; 
 
"> 
 
\t </p> 
 
\t <p class="login-password"> 
 
\t \t <label for="password">Mot de passe</label> <input type="password" name="password" id="user_pass" class="input" value="" size="20" placeholder="Password" style=" 
 
    height: 36px; 
 
"> 
 
\t </p> 
 
\t <p class="login-remember"> 
 
\t \t <label><input name="rememberme" type="checkbox" id="rememberme" value="forever"> Remember Me</label> 
 
\t </p> 
 
\t <p class="login-submit"> 
 
\t \t <input type='submit' name='enter' id="wp-submit" class="button-primary" value="Sign In" style=" 
 
    width: 110px; 
 
    height: 36px; 
 
"/> 
 
\t </p> 
 
</fieldset> \t 
 
</div> 
 
\t \t </form>

任何幫助表示讚賞。

+0

創建2種不同的形式。 –

+0

用提交按鈕創建兩個不同名稱的不同名稱。 – Akshay

+0

print $ _POST並檢查你提交的內容 –

回答

1

創建兩個提交按鈕。給兩個不同值的提交輸入同名。

<input type="submit" name="btn_name" value="First Button"/> 
<input type="submit" name="btn_name" value="Second Button"/> 

,並檢查它一樣,

​​
+0

我正在嘗試這個解決方案,但它不能這樣做!你可以使用我的代碼! – ilham

0

請加名稱標籤在這兩個按鈕,並檢查使用isset()函數功能

<input type="submit" name="btn1" value="btn1" /> 
<input type="submit" name="btn2" value="btn2" /> 


if ($_SERVER['REQUEST_METHOD'] === 'POST') { 
    //something posted 

    if (isset($_POST['btn1'])) { 
     // btn1 
    } else { 
     //btn2 
    } 
} 
+0

我正在嘗試使用此解決方案,但它無法做到這一點!你可以使用我的代碼! – ilham

相關問題