2016-09-21 112 views
-3
<?php 
$con=mysqli_connect("localhost","root","","ok_db")or die(mysqli_connect_error()); 
$output = 'arslan'; 
// collect 
if (isset($_POST['search'])) { 

    $searchq = $_POST['search']; 
    $searchq = preg_replace("#[^0-9a-z]#i","",$searchq); 

    $query = mysqli_query($con,"SELECT * FROM user_data WHERE fname LIKE '%$searchq%'") or die("Could not search."); 
    $count = mysqli_num_rows($query); 
    if($count == 0) { 
     $output = 'No results found.'; 
    } else { 
     while($row = mysqli_fetch_array($query)) { 
      $itemname = $row['fname']; 
      $description = $row['lname']; 
      $image = $row['id']; 

      $output .= '<div>'.$itemname.' '.$description.'</div>'; 
     } 
    } 
} 
else{ 

    echo "no" ; 

} 
?> 

<html> 
<head> 
<title>searching</title> 
</head> 
<body> 
<form action="search.php" method="POST"> 
    <input type="text" name="search" placeholder="Search"> 
    <input type="submit" value=">>" /> 
</form> 
</body> 

<?php 
print $output; 
?> 
</html> 

此代码在我的本地主机(XAMPP)上正常工作,但没有在PhpStorm中回显任何内容,isset函数在那里不工作,并始终显示输出“no”。PhpStorm isset函数不工作?

我的PhpStorm设置有问题,因为它在localhost上运行正常?

+3

当你说phpstorm不显示任何东西,你的意思是你使用'在浏览器中查看'选项?如果你只是在本地加载文件,并不会呈现任何PHP,因为它没有服务器可以通过。 – DevDonkey

+0

您必须使用PhpStorm自己的内置简单Web服务器..哪个ATM在处理POST请求时遇到问题。只需配置PhpStorm即可使用XAMPP安装中的Apache - http://stackoverflow.com/a/34787827/783119。当这不起作用时,浏览器地址栏中显示的URL是什么? – LazyOne

+0

顺便说一句 - 在技术上'isset'不是一个函数,但语言结构的行为像函数 – LazyOne

回答

0

PHP STORM是一个用于编写代码的IDE,对此没有任何影响。

我建议做

print_r($_POST['search']); 

,并确保它实际上是填补了,可能是笔误。

+0

print_r($ _ POST ['search]);显示未定义索引的错误'搜索' –

+0

这意味着它尚未设置 – virepo