gpt4 book ai didi

php - 使用 javascript 和 php 创建一个 onChange 选择下拉菜单,但它不起作用

转载 作者:行者123 更新时间:2023-11-29 22:16:28 25 4
gpt4 key购买 nike

我要做的是在苏格兰创建一个由32个不同位置的下拉容器。 div 中的每篇文章 WHERE location = Glasgow。

我没有错误消息,也没有任何类型的识别表明我的代码有效,因为当我从下拉列表中选择四个之一时,它绝对没有任何作用。

可以来清理并纠正我到目前为止所做的事情吗?我将非常感激!

这是我正在使用的文件:

标题.php

<html>
<head>
<script src="http://code.jquery.com/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$('#location').change(function(){
//Retrieve Content from the back-end PHP page, and pass the ID selected
var url = 'location.php?location=' + $(this).val();
$('#txtHint').load(url);
});
});
</script>

</head>
<body>
<div id="header">
<div class="headerLeftContent">
<select id='location'>
<option href="Link to a dynamic page with all the content from glasgow" value="Glasgow">Glasgow</option>
<option href="Link to a dynamic page with all the content from x" value="x">x</option>
<option href="Link to a dynamic page with all the content from test" value="test">test</option>
<option href="Link to a dynamic page with all the content from edinburgh" value="Edinburgh">Edinburgh</option>
</select>
<div id='txtHint'></div>
</div>
</div>

</body>
</html>

位置.php

<?php
$connect = mysql_connect('xxxxxx', 'xxxxxx', 'xxxxxx');
$select_db = mysql_select_db('xxxxxx');

$location = $_REQUEST['location'];

$query = "SELECT * FROM podContent WHERE location = '.$location.'";

while($row = mysql_fetch_array($query))
{
echo $row['text'];
}

mysql_close($connect);

?>

关于“SQL 注入(inject)”或“mysql”如何成为“PDO”的任何评论都是不需要的,因为我确实理解这一点,但我目前只是在测试并会对此进行修改。

谢谢。

最佳答案

在您的 MySQL 查询中连接您的位置名称似乎有一个错误,并且它不匹配任何内容(所以没有任何内容被回显返回)。改变这个:

$query = "SELECT * FROM podContent WHERE location = '.$location.'";

$query = "SELECT * FROM podContent WHERE location = '$location'";

(除非你的数据库中有像 .Glasgow. 这样的东西......)

然后你必须按照 Alon 的建议调用 mysql_query($query)

关于php - 使用 javascript 和 php 创建一个 onChange 选择下拉菜单,但它不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14903822/

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