我試圖解決這個問題,在截止日期即將到來之前,所以任何幫助表示讚賞。獲取搜索輸入使用的是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();
}
?>
腳本的輸出是什麼? – wroniasty
點擊提交後會發生什麼? – TJHeuvel
單擊提交時沒有任何反應。 但如果我獨立運行腳本的HTML - 腳本的輸出是一個表,就像在代碼中,用css文件樣式,這就是當我用%s替換%_GET ['搜索框'] – Bundy