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クエリとして使用する検索ボックス入力フィールドの値を取得する必要があります。私のスクリプトは、テストのために$_GET['searchbox']を's'に置き換えたときに機能します。何らかの理由で、フォームを送信しても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 または開発者ツールを使用して、サーバーに渡されるデータを確認することをお勧めします。クロムでは、ネットワークタブを見て、ファイアバグについてはよくわかりません。また、フォームのターゲット属性に関係していると思います。結果は正当なフレーム名ですか?

于 2012-06-08T14:59:37.773 に答える