Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/perl/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
搜索表单中PHP的MySQL查询问题_Php_Mysql_Get - Fatal编程技术网

搜索表单中PHP的MySQL查询问题

搜索表单中PHP的MySQL查询问题,php,mysql,get,Php,Mysql,Get,我编写了一个基本的PHP站点,它将参数从一个页面传递到另一个页面,并查询mysql数据库 我已经检查了参数是否通过了OK,但是查询中的where参数似乎不起作用。有人能帮忙吗 网站是www.retroseek.co.uk,搜索框在底部。非常感谢 <!DOCTYPE html> <html> <head> <title>Retro Computing Resource - RetroSeek Search</title> <

我编写了一个基本的PHP站点,它将参数从一个页面传递到另一个页面,并查询mysql数据库

我已经检查了参数是否通过了OK,但是查询中的where参数似乎不起作用。有人能帮忙吗

网站是www.retroseek.co.uk,搜索框在底部。非常感谢

<!DOCTYPE html>

<html>

<head>

<title>Retro Computing Resource - RetroSeek Search</title>

<meta charset="UTF-8">


<style>
table, td, th {
    border: 1px solid green;
}

th {
    background-color: green;
    color: white;
}
</style>


</head>

<body>

<h1>Results from the RetroSeek Search Engine</h1>

<?php 

echo "<h1>Testing the GET has worked " . $_GET["query"] . "</h1>";


require( '../connect_db.php' ) ;

$query = $_GET['query']; 


$query = htmlspecialchars($query); 


$query = mysql_real_escape_string($query);

echo "<h1>Testing the GET has worked " . $_GET["query"] . "</h1>";



    $min_length = 4;
    // you can set minimum length of the query if you want


$q = "SELECT fgames.fgname, fgames.fgprorg, fgames.fgprbud, fgames.fgratng, fgames.fgprdsk, ftypes.fttname, frefs.fryymm, frefs.frpage, frefs.frissue, fmagzne.fmname, frefcde.ffname
FROM fgames, ftypes,frefs, fmagzne,frefcde
WHERE ftypes.fttype = fgames.fgtype
and   fgames.fglink = frefs.frlink2
and   frefs.frentry = frefcde.ffentry
and   frefs.frmag = fmagzne.fmmag 
and   fgames.fgname LIKE '%".$query."%'" ;



$r = mysqli_query( $dbc , $q ) ;

if( $r ) 
{


  echo '<table><tr><th>FGNAME</th><th>FGPRORG</th><th>FGRBUD</th><th>FGRATNG</th><th>FGRDSK</th><th>FTTTNAME</th><th>FRYYMM</th><th>FRPAGE</th><th>FRISSUE</th><th>FMNAME</th><th>FFNAME</th></tr>';

  while ( $row = mysqli_fetch_array( $r , MYSQLI_ASSOC ) ) 
  {
    echo '<tr><td>'.$row['fgname'].'</td><td>'.$row['fgprorg'].'</td><td> '.$row['fgprbud'].' </td><td>'.$row['fgratng'].' </td><td>'.$row['fgprdsk'].' </td><td>'.$row['fttname'].'</td><td> '.$row['fryymm'].'</td><td> '.$row['frpage'].'</td><td> '.$row['frissue'].' </td><td>'.$row['fmname'].' </td><td>'.$row['ffname'].'</td></tr>';
  }
  echo '</table>';
}

else
{
  echo '<p>' . mysqli_error( $dbc ) . '</p>'  ;
}

show_records($dbc);

# Close the connection.
mysqli_close( $dbc ) ;
?>



<h3>Contact me at jonesypeter@hotmail.com if you would like any information on my plans for this website. Please send me as much feedback and suggestions as possible.</h3>
<h4>Last updated on 28 January 2015</h4>

</body>
</html>

追溯计算资源-追溯搜索
表,td,th{
边框:1px纯绿色;
}
th{
背景颜色:绿色;
颜色:白色;
}
来自RetroSeek搜索引擎的结果
联系我jonesypeter@hotmail.com如果你想了解我的网站计划的任何信息。请给我尽可能多的反馈和建议。
最后更新日期:2015年1月28日

如果参数中有特殊字符或空格,有时使用$\u GET可能有点困难

我看到您处理了$\u GET['query'],但是如果您有空格,您可以得到不同的结果

请回显$q并尝试在phpMyAdmin或mysql终端中运行结果。 如果它能工作并返回所需的数据,请将其放在代码的最上面:

<?php
error_reporting(E_ALL);
ini_set('display_errors', TRUE);
ini_set('display_startup_errors', TRUE);

仅供参考,就我个人而言,我觉得这更容易阅读:

"
SELECT g.fgname
     , g.fgprorg
     , g.fgprbud
     , g.fgratng
     , g.fgprdsk
     , t.fttname
     , r.fryymm
     , r.frpage
     , r.frissue
     , m.fmname
     , frefcde.ffname
  FROM fgames g
  JOIN ftypes t
    ON t.fttype = g.fgtype
  JOIN frefs r
    ON r.frlink2 = g.fglink 
  JOIN fmagzne m
    ON m.fmmag = r.frmag 
  JOIN frefcde
    ON frefcde.ffentry = r.frentry 
 WHERE g.fgname LIKE '$query';
";

你能回显$q并粘贴到你的问题上吗?与$\u GET[“query”]相同?您混合了
mysql\u*
mysqli\u*
函数。那不行。不要应用多层转义。转义数据仅用于应用它的用途。具体来说,删除此
$query=htmlspecialchars($query)。在向浏览器输出数据时应用它。如果用类似的硬编码值替换“%”“%$query.”“%”,查询是否有效?您好,感谢所有的反馈和对我的温和对待,我添加了错误报告,其中给出:警告:mysql_real_escape_string()[function.mysql real escape string]:第48行/home/sites/retroresource.co.uk/public_html/retroseek.php中的用户'retroresource.co.uk'@'10.0.1.170'(使用密码:否)访问被拒绝警告:第48行的mysql_real_escape_string()[function.mysql real escape string]:无法在/home/sites/retroresource.co.uk/public_html/retroseek.php中建立到服务器的链接,我已经回显了查询,它似乎不包含参数:现在似乎正在工作,不确定我做了什么,但如果您想查看代码,请告诉我。谢谢,让我看看。它会给你一个错误:$query=mysql\u real\u escape\u string($query);因为你在使用mysqli,而不是像jayblanchard说的那样使用mysql。您需要将其更改为mysqli。看来你成功了。现在可以用了吗?好。:)再见!