2013-04-12 18 views
0

我有一個網站在HTML和一個網頁中,我有按鈕來訪問者的DJ的配置文件。我如何在php中添加信息到url?

每個按鈕都會將訪問者帶到不同的dj配置文件。 我在html中創建了一個頁面,該頁面轉到XML文檔以獲取dj的信息。所以,我的問題是,我如何在php頁面的鏈接中添加dj的名稱,以便他可以保留個人鏈接?

我試過get屬性,但我也需要這個帖子,爲了讓PHP獲取該dj的信息。

djspace.html頁面的HTML有這樣的:

<form name="form" id="form" method="post" action="allProfiles.php"> 
    <input type="submit" name="dj_name" value="Blowdrop"/> 
</form> 
... 
<form name="form" id="form" method="post" action="allProfiles.php"> 
    <input type="submit" name="dj_name" value="Psychokiller"/> 
</form> 

,然後我allprofiles.php頁:

<?php 
    $counter = 0; 
    $dj_name = ($_POST['dj_name']); 
    $xml = simplexml_load_file("Profiles.xml"); 

    foreach ($xml as $newprofile){ 
    if($xml->newprofile[$counter]->Anome == $dj_name){ 
     $Anome   = $xml->newprofile[$counter]->Anome; 
     $nacionalidade = $xml->newprofile[$counter]->nacionalidade; 
     $naturalidade = $xml->newprofile[$counter]->naturalidade; 
     $residencia  = $xml->newprofile[$counter]->residencia; 
     $emprego   = $xml->newprofile[$counter]->emprego; 
     $generos   = $xml->newprofile[$counter]->generos; 
     $disponibilidade = $xml->newprofile[$counter]->disponibilidade; 
     $partilha  = $xml->newprofile[$counter]->partilha; 
     $sitios   = $xml->newprofile[$counter]->sitios; 
     $tempo   = $xml->newprofile[$counter]->tempo; 
     $editora   = $xml->newprofile[$counter]->editora; 
     $promotora  = $xml->newprofile[$counter]->promotora; 
     $influencias  = $xml->newprofile[$counter]->influencias; 
     $fblink   = $xml->newprofile[$counter]->fb; 
     $scloud   = $xml->newprofile[$counter]->scloud; 
     $mail   = $xml->newprofile[$counter]->email; 
     $img    = $xml->newprofile[$counter]->foto; 
    } 
    $counter = $counter + 1; 
} 

?> 

我可以得到所有的信息,但我如果我申請的get,我不能。

很明顯,如果你直接進入php頁面,你會得到任何信息。 http://roundhillevents.com/allProfiles.php

但是先進入此鏈接,然後點擊dj的dj空間,然後單擊您要查看的信息。

+1

你正在做簡單的數據檢索後。爲什麼不使用GET,例如'Blowdrop'? –

+0

提取($ xml-> newprofile [$ counter]);這段代碼是不可讀的... ^^ – bwoebi

+0

抱歉bwoebi,我沒有明白你的意思。我在那裏做什麼? –

回答

0

這是因爲您在php中使用$ _POST。嘗試使用$ _REQUEST或$ _GET全局變量,而不是$ _ POST

試試這個

<?php 
$counter = 0; 
$dj_name = ($_REQUEST['dj_name']); 
$xml = simplexml_load_file("Profiles.xml"); 
foreach ($xml as $newprofile){ 
if($xml->newprofile[$counter]->Anome == $dj_name){ 
$Anome = $xml->newprofile[$counter]->Anome; 
$nacionalidade = $xml->newprofile[$counter]->nacionalidade; 
$naturalidade = $xml->newprofile[$counter]->naturalidade; 
$residencia = $xml->newprofile[$counter]->residencia; 
$emprego = $xml->newprofile[$counter]->emprego; 
$generos = $xml->newprofile[$counter]->generos; 
$disponibilidade = $xml->newprofile[$counter]->disponibilidade; 
$partilha = $xml->newprofile[$counter]->partilha; 
$sitios = $xml->newprofile[$counter]->sitios; 
$tempo = $xml->newprofile[$counter]->tempo; 
$editora = $xml->newprofile[$counter]->editora; 
$promotora = $xml->newprofile[$counter]->promotora; 
$influencias = $xml->newprofile[$counter]->influencias; 
$fblink = $xml->newprofile[$counter]->fb; 
$scloud = $xml->newprofile[$counter]->scloud; 
$mail = $xml->newprofile[$counter]->email; 
$img = $xml->newprofile[$counter]->foto; 
} 
$counter = $counter + 1; 
} 
?> 
+0

非常感謝你們所有人。我幫你解決了2個問題。 我使用鏈接,而不是使用按鈕,並使用REQUEST我可以easyli訪問所有的信息。我很好。謝謝你們。 –

1

由於@Marc乙建議,使用環節,而不是與按鈕形式。

如果您想繼續使用按鈕,請將method="post"更改爲method="get"。然後,瀏覽器將dj引用添加到頁面的URL中。

當然,您需要在您的PHP代碼中使用$_GET['dj_name'])而不是$_POST['dj_name']。這適用於兩種情況,帶有GET方法和鏈接的按鈕。