ellifant Posted May 9, 2013 Share Posted May 9, 2013 I'm really new to PHP & SQL. I'm trying to create a search function for a research database. I keep getting the following error: request "Could not execute SQL query" SELECT * title GROUP BY keyword ORDER BY id. How do I fix it?! <?php error_reporting(0); include("/config2.php"); ?> <!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> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>MySQL table search</title> <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.0/jquery.min.js"></script> <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/jquery-ui.min.js"></script> <link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" rel="stylesheet" type="text/css"/> <style> BODY, TD { font-family:Arial, Helvetica, sans-serif; font-size:12px; } </style> </head> <body> <form id="form1" name="form1" method="post" action="file:///C|/Users/lmfish89.Laura-PC/AppData/Local/Temp/Temp1_mysql-search-table.zip/search.php"> <label for="title">Title</label> <input name="title" type="text" id="title" size="10" value="<?php echo $_REQUEST["title"]; ?>" /> <label for="author">Author</label> <input name="author" type="text" id="author" size="10" value="<?php echo $_REQUEST["author"]; ?>"/> <label>Abstract:</label> <input type="text" name="abstract" id="abstract" value="<?php echo stripcslashes($_REQUEST["abstract"]); ?>" /> <label>Keyword</label><input type="text" name="keyword" id="keyword" value="<?php echo stripcslashes($_REQUEST["keyword"]); ?>" /> <?php $sql = "SELECT * title ".$SETTINGS["database"]." GROUP BY keyword ORDER BY id"; $sql_result = mysql_query ($sql, $config2) or die ('request "Could not execute SQL query" '.$sql); while ($row = mysql_fetch_assoc($sql_result)) { echo "<option value='".$row["keyword"]."'".($row["keyword"]==$_REQUEST["keyword"] ? " selected" : "").">".$row["keyword"]."</option>"; } ?> </select> <input type="submit" name="butauthorn" id="butauthorn" value="Filter" /> </label> <a href="file:///C|/Users/lmfish89.Laura-PC/AppData/Local/Temp/Temp1_mysql-search-table.zip/search.php"> reset</a> </form> <br /><br /> <table width="700" border="1" cellspacing="0" cellpadding="4"> <tr> <td width="90" bgcolor="#CCCCCC"><strong>Title </strong></td> <td width="95" bgcolor="#CCCCCC"><strong>Author(s)</strong></td> <td width="159" bgcolor="#CCCCCC"><strong>Abstract</strong></td> <td width="191" bgcolor="#CCCCCC"><strong>Keywords</strong></td> <td width="113" bgcolor="#CCCCCC"><strong>Link</strong></td> </tr> <?php if ($_REQUEST["string"]<>'') { $search_string = " AND (keyword LIKE '%".mysql_real_escape_string($_REQUEST["string"])."%' OR abstract LIKE '%".mysql_real_escape_string($_REQUEST["string"])."%')"; } if ($_REQUEST["keyword"]<>'') { $search_keyword = " AND keyword='".mysql_real_escape_string($_REQUEST["keyword"])."'"; } if ($_REQUEST["title"]<>'' and $_REQUEST["author"]<>'') { $sql = "SELECT * title ".$SETTINGS["database"]." WHERE title_date >= '".mysql_real_escape_string($_REQUEST["title"])."' AND author_date <= '".mysql_real_escape_string($_REQUEST["author"])."'".$search_string.$search_keyword; } else if ($_REQUEST["title"]<>'') { $sql = "SELECT * title ".$SETTINGS["database"]." WHERE title_date >= '".mysql_real_escape_string($_REQUEST["title"])."'".$search_string.$search_keyword; } else if ($_REQUEST["author"]<>'') { $sql = "SELECT * title ".$SETTINGS["database"]." WHERE author_date <= '".mysql_real_escape_string($_REQUEST["author"])."'".$search_string.$search_keyword; } else { $sql = "SELECT * title ".$SETTINGS["database"]." WHERE id>0".$search_string.$search_keyword; } $sql_result = mysql_query ($sql, $config2) or die ('request "Could not execute SQL query" '.$sql); if (mysql_num_rows($sql_result)>0) { while ($row = mysql_fetch_assoc($sql_result)) { ?> <tr> <td><?php echo $row["title"]; ?></td> <td><?php echo $row["author"]; ?></td> <td><?php echo $row["abstract"]; ?></td> <td><?php echo $row["keyword"]; ?></td> <td><?php echo $row["link"]; ?></td> </tr> <?php } } else { ?> <tr><td colspan="5">No results found.</td> <?php } ?> </table> </body> </html> Quote Link to comment Share on other sites More sharing options...
Solution requinix Posted May 9, 2013 Solution Share Posted May 9, 2013 SELECT * title GROUP BY keyword ORDER BY idLook at that query. Does anything seem wrong about it? If not, take a step or two away from your monitor and look again. Quote Link to comment Share on other sites More sharing options...
ellifant Posted May 10, 2013 Author Share Posted May 10, 2013 Bless you. I'm a moron. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.