在PHP中有没有办法在会话中存储$variable中的$variable
我创建了一个网页,在那里你可以搜索植物的学名。在搜索文本中键入植物名称它将在搜索结果中为您提供结果(如谷歌和facebook搜索栏等实时搜索)。例如:当您在搜索输入中键入C时,您将在搜索结果中获得与C相关的搜索。就像在搜索输入中键入的C一样,在搜索结果中,它将开始显示黄瓜(Cucumissativus)、辣椒(Pencicum annium)等 现在我想当你在搜索结果中点击Cucumber(Cucumis sativus)时,它必须指向home.php/Cucumber。或者当用户点击辣椒(辣椒一年生),它必须指向home.php/Capsicum 在body标签中的home.php上,我想用植物的学名显示植物的名称。以及与植物搜索结果相关的para tag信息 index.php在PHP中有没有办法在会话中存储$variable中的$variable,php,jquery,mysql,Php,Jquery,Mysql,我创建了一个网页,在那里你可以搜索植物的学名。在搜索文本中键入植物名称它将在搜索结果中为您提供结果(如谷歌和facebook搜索栏等实时搜索)。例如:当您在搜索输入中键入C时,您将在搜索结果中获得与C相关的搜索。就像在搜索输入中键入的C一样,在搜索结果中,它将开始显示黄瓜(Cucumissativus)、辣椒(Pencicum annium)等 现在我想当你在搜索结果中点击Cucumber(Cucumis sativus)时,它必须指向home.php/Cucumber。或者当用户点击辣椒(辣椒
<!DOCTYPE html>
<html>
<head>
<title>Search</title>
<style type="text/javascript"
src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"> </style>
<style type="text/javascript">
function searchq() {
var searchTxt = $("input[name='search']").val();
$.get("search.php", {searchVal: searchTxt}, function(output) {
$("#output").html(output);
});
}
</script>
</head>
<body>
<form action="index.php" method="post">
<input type="text" name="search" id="myInput1" autocomplete="off"
placeholder="Search username..." onkeydown="searchq(); " />
<input type="submit" value=">>"/>
</form>
<br>
<div id="output"></div>
</body>
</html>
<?php
$con = mysqli_connect('localhost', 'root');
mysqli_select_db($con, 'plant');
$output = '';
if (isset($_GET['searchVal'])) {
$searchq = $_GET['searchVal'];
$sql = "select * from type where plant like '%$searchq%'";
$query = mysqli_query($con, $sql) or die("could not search");
$count = mysqli_num_rows($query);
if ($count == 0) {
$output = 'There is no serach result';
} else {
while ($row = mysqli_fetch_array($query)) {
$plantname = $row['plant'];
$sciencename = $row['species'];
$id = $row['id'];
$output .= '<div>' . $plantname . ' ' . $sciencename . '</div>';
}
}
}
echo '<a herf="home.php/">' . $output . '</a></div>';
?>
搜寻
函数searchq(){
var searchTxt=$(“输入[name='search']”)val();
$.get(“search.php”,{searchVal:searchTxt},函数(输出){
$(“#输出”).html(输出);
});
}
search.php
<!DOCTYPE html>
<html>
<head>
<title>Search</title>
<style type="text/javascript"
src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"> </style>
<style type="text/javascript">
function searchq() {
var searchTxt = $("input[name='search']").val();
$.get("search.php", {searchVal: searchTxt}, function(output) {
$("#output").html(output);
});
}
</script>
</head>
<body>
<form action="index.php" method="post">
<input type="text" name="search" id="myInput1" autocomplete="off"
placeholder="Search username..." onkeydown="searchq(); " />
<input type="submit" value=">>"/>
</form>
<br>
<div id="output"></div>
</body>
</html>
<?php
$con = mysqli_connect('localhost', 'root');
mysqli_select_db($con, 'plant');
$output = '';
if (isset($_GET['searchVal'])) {
$searchq = $_GET['searchVal'];
$sql = "select * from type where plant like '%$searchq%'";
$query = mysqli_query($con, $sql) or die("could not search");
$count = mysqli_num_rows($query);
if ($count == 0) {
$output = 'There is no serach result';
} else {
while ($row = mysqli_fetch_array($query)) {
$plantname = $row['plant'];
$sciencename = $row['species'];
$id = $row['id'];
$output .= '<div>' . $plantname . ' ' . $sciencename . '</div>';
}
}
}
echo '<a herf="home.php/">' . $output . '</a></div>';
?>
请在index.php中更正这一行
<style type="text/javascript">
与
有很多方法可以做到这一点 将工厂名称作为GET参数传递不是一个选项吗 你可以
echo "<a href='home.php?plantname={$plantname}' target='_blank'>{$output}</a></div>";
你的问题标题是关于会话的,但我看不到你在这里的任何地方使用它们。我也看不出使用它们有什么意义,因为您显然想要获取当前请求中发送的信息。如果您实际的问题是如何获取值
Cucumber
,当请求home.php/Cucumber
时,答案称为PATH\u INFO。我投票决定结束,因为不清楚您在问什么,没有努力格式化代码可读性。以及如何在home上打印Cucumber及其scientific。phpOT:广泛接受sql注入:我拒绝了编辑,因为它通过更改标记对snipet有害。这是我的错误,很抱歉。它引发了异常还是什么?你正在运行什么PHP版本?保留它我删除了我的所有项目。你想删除你的问题吗?