我试图在截止日期即将到来之前解决这个问题,以便获得任何帮助。
<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查询。我的脚本工作,因为我用'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 :(得分:0)
也许是一个远景,但'type =“submit”'中有一个空格。如果空白区域存在,您的浏览器无法将提交按钮识别为提交按钮,因此无法提交您的表单。
答案 1 :(得分:0)
如果您在Firefox或Chrome上测试表单,我建议使用firebug或开发人员工具查看传递给服务器的数据。在chrome中,我会查看网络选项卡,对firebug不太确定。 另外我认为可能与表单上的target属性有关。结果是合法的框架名称吗?