gpt4 book ai didi

javascript - Php 表单不起作用,作为 2 个单独的页面工作,但不是 1 个合并的页面

转载 作者:行者123 更新时间:2023-11-30 09:55:14 25 4
gpt4 key购买 nike

好的,嗨,基本上我有一个 PHP 表单,所以您在表单中输入一些内容,然后在下一页上它会根据您输入的内容显示一些数据。我试图将其放入一个网页而不是 2 . 它作为 2 个单独的网页工作正常,但当我尝试将它们组合时它不起作用。

自从这个人第一次加载网页后,就不会提交任何表单,这意味着它无法加载我完成的任何数据

if (player1 != "")

这样,如果 php 表单已提交,那么那将是正确的。当然,这是建立在不提交它等于“”的假设之上的。我不确定这是否正确,因此需要注意这一点。

这是表格

<form action="hacker.php" method="post">
<table>
<tr>
<td>Hackers name:</td>
<td>
<input type="text" name="player" value="" maxlength="100" />
</td>
</tr>
<tr>
<tr>
<td>&nbsp;</td>
<td>
<input type="submit" value="Submit" />
</td>
</tr>
</table>
</form>

这是表单将信息发送到的页面 (hacker.php):

<script>
var yqlcallback = function(data) {
var results = data.query.results;
document.body.innerHTML = results.span;
var percentage = results.span;
rating = percentage.slice(0, -1);
if (rating > 30) {
document.body.innerHTML = "This player has now been banned";
} else {
document.body.innerHTML = "Please submit further evidence to have this person banned";
}
};

</script>

<script id="myscript"></script>

<?php
$player = $_POST['player'];
?>
<script>
var player1 = "<?php echo $player; ?>";
var link1 = "https://query.yahooapis.com/v1/public/yql?q=select%20content%20from%20html%20where%20url%3D%22http%3A%2F%2Fwww.team-des-fra.fr%2FCoM%2Fbf3.php%3Fp%3D";
var link2 = "%22%20and%20xpath%3D'%2F%2F*%5B%40id%3D%22content%22%5D%2Fdiv%5B3%5D%2Fdiv%2Fsp an'&format=json&callback=yqlcallback";
var link = link1 + player1 + link2;
document.getElementById('myscript').setAttribute('src', link);
</script>

我试图将这 2 个合并到一个名为 index.php 的 php 文件中,这样 javascript 就只会在从来源获取信息时才加载数据,但它似乎不起作用。她是我所拥有的:表单操作是 index.php,页面名称是 index.php,我这样做是因为我不希望它在提交表单后重定向到单独的链接。

<!--This is the form used to submit the info-->
<center>
<form action="index.php" method="post">
<table>
<tr>
<td>Hackers name:</td>
<td>
<input type="text" name="player" value="" maxlength="100" />
</td>
</tr>
<tr>
<tr>
<td>&nbsp;</td>
<td>
<input type="submit" value="Submit" />
</td>
</tr>
</table>
</form>

<!--This gets the data from another website and displays text depending upon what the value of that data is-->
<script>
if (player1 != "") {
var yqlcallback = function(data) {
var results = data.query.results;
document.body.innerHTML = results.span;
var percentage = results.span;
rating = percentage.slice(0, -1);
if (rating > 30) {
document.body.innerHTML = "This player has now been banned";
} else {
document.body.innerHTML = "Please submit further evidence to have this person banned";
}
};
};

</script>

<!--This is changed so that the src is dependant upon what the person entered into the form, code that does that is below. Code above then reads the data sheet this gets-->
<script id="myscript"></script>


<!--This gets the value from the php form then converts it to javascript and creates a link with it used to get the data on that person-->
<?php
$player = $_POST['player'];
?>
<script>
var player1 = "<?php echo $player; ?>";
var link1 = "https://query.yahooapis.com/v1/public/yql?q=select%20content%20from%20html%20where%20url%3D%22http%3A%2F%2Fwww.team-des-fra.fr%2FCoM%2Fbf3.php%3Fp%3D";
var link2 = "%22%20and%20xpath%3D'%2F%2F*%5B%40id%3D%22content%22%5D%2Fdiv%5B3%5D%2Fdiv%2Fspan'&format=json&callback=yqlcallback";
var link = link1 + player1 + link2;
if (player1 != "") {
document.getElementById('myscript').setAttribute('src', link);
}
</script>

最佳答案

在上面的脚本中选中后,您正在定义 player1 变量。尝试移动

<script>
if (player1 != "") {
var yqlcallback = function(data) {
var results = data.query.results;
document.body.innerHTML = results.span;
var percentage = results.span;
rating = percentage.slice(0, -1);
if (rating > 30) {
document.body.innerHTML = "This player has now been banned";
} else {
document.body.innerHTML = "Please submit further evidence to have this person banned";
}
};
};

</script>

到另一个脚本的下方。

关于javascript - Php 表单不起作用,作为 2 个单独的页面工作,但不是 1 个合并的页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34376966/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com