我有一个html网站,在一个页面中,我有按钮,让游客到dj的个人资料。
每个按钮将访问者带到不同的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的空间,然后点击在一个你想看到的信息。
正如@Marc B建议的那样,使用链接代替带有按钮的表单。
如果出于某种原因想继续使用按钮,请将method="post"
更改为method="get"
。然后浏览器为您添加dj引用到页面的URL。
当然,您需要在PHP代码中使用$_GET['dj_name'])
而不是$_POST['dj_name']
。这两种情况下,按钮与GET
方法和链接
这是因为您在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;
}
?>