2012-06-08 88 views
0

我試圖解決這個問題,在截止日期即將到來之前,所以任何幫助表示讚賞。獲取搜索輸入使用的是PHP腳本,不工作?

<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格式。

我需要獲取searchbox輸入字段的值作爲php腳本中的sql查詢使用。我的腳本作爲ive用'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(); 
} 
?> 
+0

腳本的輸出是什麼? – wroniasty

+1

點擊提交後會發生什麼? – TJHeuvel

+0

單擊提交時沒有任何反應。 但如果我獨立運行腳本的HTML - 腳本的輸出是一個表,就像在代碼中,用css文件樣式,這就是當我用%s替換%_GET ['搜索框'] – Bundy

回答

0

也許很長,但'type =「submit」'有一個空白區域。也許您的瀏覽器無法識別您的提交按鈕作爲提交按鈕,如果有空白,因此無法提交您的表單。

0

如果您在Firefox或Chrome上測試您的表單,我會建議使用Firebug或開發人員工具查看傳遞到服務器的數據。在鉻我會看看網絡標籤,不太確定螢火蟲。 另外我認爲這可能與您的目標屬性在窗體上。結果是一個合法的框架名稱?