gpt4 book ai didi

php - 如何禁用 % 输出所有内容

转载 作者:行者123 更新时间:2023-11-29 12:15:31 24 4
gpt4 key购买 nike

嘿,我有一个搜索字段,我正在从数据库中搜索一些内容,现在我在测试后看到了问题,如果我在搜索字段中输入“%”,它将输出我准备好搜索的所有内容。有办法禁用这个吗?

<h3>Search Share Details</h3>
<p>You may search either by company name or issue date</p>

<form name = "search" method = "get">
<input type = "text" name = "share" size = "40" maxlength="50">
<input type = "submit" value = "Search">
</form>

获取内容连接数据库,获取结果并打印

function get_contents() {

if(isset($_GET['share']))
{
$conn = db_connect();
$shares = get_shareSearch($conn);
db_disconnect($conn);
$contents = array('shares' => $shares);
return $contents;
}
else
{
$conn = db_connect();
$shares = get_share($conn);
db_disconnect($conn);
$contents = array('shares' => $shares);
return $contents;
}
}


function print_contents($contents)
{

if(count($contents['shares']) == 0)
{
echo "<script type = 'text/javascript'>alert('Sorry but share is not found! Q_Q');</script>";

}
else
{
?>
<table>
<tr>
<th>Company Name</th>
<th>Rate</th>
<th>Issue Date</th>

</tr>
<?php
foreach ($contents['shares'] as $share)
{
print "<tr>";
$identifier = urlencode($share['SHAREID']);
print "<td><a href='share-details.php?id={$identifier}'>{$share['COMPANY']}</a></td>";
print "<td>{$share['RATE']}</td>";

$issue_date = $share['ISSUE_DATE'];
$issue_date = $issue_date === NULL ? "&lt; not available &gt;" : $issue_date;
print "<td>{$issue_date}</td>";
print "</tr>";
}
?>
</table>
<?php
}
}
//require("shares.php");
require("search.php");
?>

查询本身

function get_shareSearch($conn) { 
$id = "";
if(isset($_GET['share'])){$id = $_GET['share'];}
$statement = db_create_statement($conn, "SELECT DISTINCT * FROM shares WHERE(company LIKE '{$id}' OR issue_date LIKE '{$id}')");
$resultset = db_fetch_resultset($statement);
return $resultset;

}

最佳答案

逃避

这是指在其前面放置一个字符以表示它应按字面意思理解:

原始声明

SELECT * FROM ikeaTable WHERE chair LIKE '5% off';

转义版本

SELECT * FROM ikeaTable WHERE chair LIKE '5\% off' ESCAPE '\';

你的

SELECT DISTINCT * FROM shares WHERE(company LIKE '\%{$id}' OR issue_date LIKE '\%{$id}') ESCAPE '\'

关于php - 如何禁用 % 输出所有内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29867770/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com