【问题标题】:get search input to use is PHP script, not working?获取要使用的搜索输入是 PHP 脚本,不起作用?
【发布时间】:2012-06-08 13:08:16
【问题描述】:

我正试图在最后期限即将到来之前解决这个问题,因此我们不胜感激。

<form id="searchdivebay" action="searchdivebay.php" method="get" target="results">
    <div class="searchbox"><input type="text" name="searchbox" id="searchboxinput"/></div>
    <div class="searchbtn"><input type ="submit" name="searchbutton" value="Search DiveBay"/></div>
</form>

是我的 html 表单。

我需要获取搜索框输入字段的值以用作 php 脚本中的 sql 查询。我的脚本就像我用 's' 替换了 $_GET['searchbox'] 来测试它一样工作。出于某种原因,在提交表单时不会启动 php 脚本,我不知道该怎么做。任何人都可以看到脚本或 html 有什么问题吗?非常感谢。

<?xml version = "1.0" encoding = "utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<title>searchdbresults</title>
<link rel="stylesheet" type = "text/css" href = "styledb.css" />
</head>

<body>  
<?php
$user = 'root';
$pass = null;
$pdo = new PDO('mysql:host=localhost; dbname=divebay;', $user, $pass);

$search = $_GET['searchbox'];
if(!isset($search)){
?>
<p style="color:white; font-size:18pt; font-family: Impact;"> You didn't search for anything!<p>
<?php
}
try{
    $stmt = $pdo->prepare('SELECT * FROM auction WHERE name LIKE ?');
    $stmt->bindValue(1, '%'. trim($search) .'%');
    $stmt->execute();



    $numrows = 0;
?>
    <table id="showresult">
<?php
    while($row = $stmt->fetch(PDO::FETCH_ASSOC)){
        $numrows++;
        $ID = $row['ID'];
        $img = $row['img'];
        $name = $row['name'];
        $owner = $row['owner'];
        $cprice = $row['cprice'];
        $iprice = $row['iprice'];
        $incprice = $row['incprice'];
        $etime = $row['etime'];
?>      
    <tr class = "resultindex">
        <td class = "imgholder"><?php echo $img; ?></td>
        <td class = "infoholder">
            <div style ="height:4px;"></div>
            <div class = "infodiv"><?php echo $name; ?></div>
            <div class = "locdiv"></div>
            <div class = "userdiv"><span class="fromuser">From user: </span></br><?php echo $owner; ?></div>
        </td>
        <td style = "width:2px; background-color:#330066;"></td>
        <td class ="priceholder">
            <div class = "currentp"><span class="currentbid">Current Bid: </span><br/><?php echo $cprice; ?></div>
            <div class = "instantp"><span class="instantbid">Instant Sale: </span><br/><?php echo $iprice; ?></div>
            <div style = "height:5px;"></div>
            <div class = "incp"><span class="nextbid">Next Bid:</span><br/>+<?php echo $incprice; ?></div>
        </td>
        <td style = "width:2px; background-color:#330066;"></td>
        <td class = "timer"><span class="timeleft">Time Left: </span><br/><?php echo $etime; ?></td>
    </tr>

<?php   
    }
?>

    <tr>
        <td colspan="4">Displaying <?php echo $numrows; ?> results</td>

    </tr>
    </table>
    </body>
    </html>
<?php
    }catch(PDOException $e){
        echo $e->getMessage();
}
?>

【问题讨论】:

  • 脚本的输出是什么?
  • 点击提交时会发生什么?
  • 点击提交时没有任何反应。但是如果我独立于 HTML 运行脚本 - 脚本的输出是一个表格,就像代码中的表格一样,使用 css 文件设置样式,那就是当我将 %_GET['searchbox'] 替换为 's'
  • 当你说什么都没有发生时,你的意思是什么都没有,它只是停留在页面上?或者它实际上是否提交到一个页面(URL 应该说 www.sitelolz.com/searchdivebay.php?searchbox=stringfunsies)并且你看到空白内容?
  • 我的意思是它只是停留在页面上,好像表单根本没有提交

标签: php html pdo


【解决方案1】:

也许是一个长镜头,但 'type ="submit"' 中有一个空格。如果存在空白,您的浏览器可能无法将您的提交按钮识别为提交按钮,因此无法提交您的表单。

【讨论】:

    【解决方案2】:

    如果您在 Firefox 或 Chrome 上测试您的表单,我建议您使用 firebug 或开发人员工具来查看传递到服务器的数据。在 chrome 中,我会查看网络选项卡,不太确定 firebug。 另外我认为这可能与表单上的目标属性有关。结果是合法的框架名称吗?

    【讨论】:

      猜你喜欢
      • 2011-09-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-03-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多