0

我正试图在最后期限即将到来之前解决这个问题,因此感谢您提供任何帮助。

<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();
}
?>
4

2 回答 2

0

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

于 2012-06-08T14:20:22.107 回答
0

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

于 2012-06-08T14:59:37.773 回答