2013-04-21 129 views
2

我是初學PHP和HTML 現在我試圖建立登錄和註冊系統... 假設在我的主頁上我有兩種形式,我希望他們出現只是當用戶點擊一個字「登錄」,或 「註冊」PHP,HTML,如何通過點擊鏈接顯示錶單?

所以我寫了一個PHP代碼這樣的:

<?php 
switch ($x) 
{ 
    case 'register' : 

?> 
     <form action="login.php" method="POST"> 
     </form> 

<?php 
    break; 

    case 'login': 
?> 
     <form action="register.php" method="POST"> 
     </form> 
<?php 
    break; 
} 
?> 

現在,我寫了一個HTML代碼那樣:

<h1>Click here to <a href =""> Login</a> or <a href =""> Register</a></h1> 

所以,在<a href ="">哪有我讓x等於'login''register'

回答

3

請嘗試查看下面的代碼!

PHP腳本:

<?php 
switch ($_GET['x']) { 
    case 'register': 
    echo '<form action="login.php" method="POST"> 
    </form>'; 
    break; 
    case 'login': 
    echo '<form action="register.php" method="POST"> 
    </form>'; 
    break; 
} 
?> 

HTML代碼:

<h1>Click here to <a href="page.php?x=login">Login</a> or <a href="page.php?x=register">Register</a></h1> 
+1

這正是我想要:) :) THX – Merna 2013-04-21 17:48:22

+0

@Merna其實,以前的代碼有錯誤,這就是我修改它的原因。 – 5ervant 2013-04-21 18:16:45

1

使用JavaScript或者jQuery的形式,這

<a href ="" id="login"> Login</a> 

<a href ="" id="register"> Register</a> 

//使用jQuery

$("#login").click(function(){ 
//Show your login form here 
}); 

$("#register").click(function(){ 
//Show your register form here 
}); 
2

那麼PHP可以做到這一點,對我來說,jQuery將是最好的。你可以用下面的代碼實現它:

jQuery: 


<script type="text/javascript"> 
$(document).ready(function(){ 
    $("#panel1").hide(); 
    $("#panel2").hide(); 
    $(".btn-slide1").click(function(){ 
     $("#panel1").slideToggle("slow"); 
    }); 

    $(".btn-slide2").click(function(){ 
     $("#panel2").slideToggle("slow"); 
    }); 
}); 
</script> 

HTML代碼:

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script> 
<p class="slide"><a href="#" class="btn-slide1">Register</a></p> 
<div id="panel1"> 
    Register Content will goes here! 
</div> 

<p class="slide"><a href="#" class="btn-slide2">Login</a></p> 
<div id="panel2"> 
    Login Content will goes here! 
</div> 

不要忘記檢查的jQuery官方頁面瞭解更多關於它的魔力!

+0

非常感謝你:) – Merna 2013-04-21 17:48:58

+0

歡迎您:) – enam 2013-04-21 17:51:22