我正在尝试为搜索数据库的网站创建一个搜索栏,但我发现它自己在搜索框中显示的代码
<form method="get" action="chalo_search.php">
<input type="search" name="k" size = "20" placeholder="Enter college name" value = "<?php echo $_GET['k'];?>" autofocus/>
<input type= "submit" value="Search"/>
</form>
此
中是否有任何错误答案 0 :(得分:4)
您在输入框中回显$ _GET ['k']。如果未定义$ _GET ['k'],则会出现此错误:
行
注意:未定义的索引:k in ... yourscript.php 在 2
(这就是搜索框中出现的内容)
检查首先定义$ _GET ['k']:
<?php if(isset($_GET['k'])){echo $_GET['k'];}?>
答案 1 :(得分:0)
试
<?php
$k = $_GET['k'];
echo "<form method='get' action='chalo_search.php'>
<input type='search' name='k' size='20' placeholder='Enter college name' value='$k' autofocus/>
<input type='submit' value='Search'/>
</form>";
?>
答案 2 :(得分:0)
在输入元素中声明“value”属性时删除多余的空格。见下文:
<input type="search" name="k" size = "20" placeholder="Enter college name" value="<?php echo $_GET['k'];?>" autofocus/>