php - 从 SQL 数据库中搜索并显示结果

标签 php html mysql sql database

我有一个 MySQL 数据库,我需要搜索交易编号(它会显示我的姓名、电子邮件和商品名称)或搜索我的电子邮件地址、姓名和购买日期,然后我会得到我的交易编号和 item_name - 除非电子邮件、姓名和购买日期都正确无误,否则我不希望出现任何内容。

我的数据库中的字段是:

iname
iemail
itransaction_id
item_name

有人可以帮忙.... 这就是我目前拥有的....

<html>

<head>
<title>Search</title>
</head>

<body bgcolor=#ffffff>

<h2>Search</h2>

<form name="search" method="post" action="findme.php">
Seach for: <input type="text" name="find" /> 


<input type="submit" name="search" value="Search" />
</form>

</body>

</html>

另存为findme.html

下一步:

<html>
<head><title>Searching for a student...</title>
</head>
<body bgcolor=#ffffff>

<?php

echo "<h2>Search Results:</h2><p>";

//If they did not enter a search term we give them an error
if ($find == "")
{
echo "<p>You forgot to enter a search term!!!";
exit;
}

// Otherwise we connect to our Database
mysql_connect("xxxx.com", "xxxx", "xxxxpw") or             die(mysql_error());
mysql_select_db("xxxx") or die(mysql_error());

// We perform a bit of filtering
$find = strtoupper($find);
$find = strip_tags($find);
$find = trim ($find);

//Now we search for our search term, in the field the user specified
$iname = mysql_query("SELECT * FROM ibn_table WHERE upper($field) LIKE'%$find%'");

//And we display the results
while($result = mysql_fetch_array( $iname ))
{
echo $result['firstname'];
echo " ";
echo $result['lastname'];
echo "<br>";
echo $result['idnumber'];
echo "<br>";
echo "<br>";
}

//This counts the number or results - and if there wasn't any it gives them a     little     message explaining that
$anymatches=mysql_num_rows($iname);
if ($anymatches == 0)
{
echo "Sorry, but we can not find an entry to match your query...<br><br>";
}

//And we remind them what they searched for
echo "<b>Searched For:</b> " .$find;
//}
?> 


</body>
</html>

保存为findme.php

这是我当前收到的错误:

搜索结果:

警告:mysql_fetch_array():在第 31 行的/hermes/bosweb25a/b409/ipg.bexgroupcouk/silverliningnetworks/Database/findme.php 中提供的参数不是有效的 MySQL 结果资源

警告:mysql_num_rows():提供的参数不是第 43 行/hermes/bosweb25a/b409/ipg.bexgroupcouk/silverliningnetworks/Database/findme.php 中的有效 MySQL 结果资源 抱歉,我们找不到与您的查询匹配的条目...

搜索:CARYS

最佳答案

SELECT * FROM ibn_table WHERE itransaction_id LIKE '%$find%'
注意 LIKE 和 '%$find%' 之间的空格

关于php - 从 SQL 数据库中搜索并显示结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15289048/

相关文章:

php - yii2中where Between查询怎么写

php - Laravel 5.2 如何在 linux 上的 cron/php 命令行上运行路由?

php - 使用 codeigniter 和 htaccess 删除 index.php 和 301 重定向

php - MySQL重复条目错误,即使它不是重复条目

php - 如何配置 Azure Web Apps 以支持 HTML 中的 PHP

javascript - 选择按钮后自动播放音频

php - 去除所有 HTML 标签,允许的除外

html - 如何访问 iFrame 中的 XML 文档?

PHP从数据库结果中对具有多个维度的数组进行分组

mysql - 如何查找未与 Waterline ORM 连接的记录