Jarel101 Posted September 1, 2011 Report Share Posted September 1, 2011 I've created a keyword mysql search, it almost works perfect. The only problem is when I don't enter a keyword into the search form and leave it blank and click the search button, I get the data from my DB table, even though I didn't enter anything in the text box? When I enter a word that's not a keyword I just get a blank page. I would like to code it in away where when I don't enter anything and hit search or enter a keyword that I haven't added, I get a message that says "no results were found" or anything to that effect. My question is how do I do this? HERES MY CODE: SEARCH RESULTS PAGE: <?php require_once('Connections/MyConnection.p… ?> <?php if (!function_exists("GetSQLValueString")) { function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { if (PHP_VERSION < 6) { $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; } $theValue = function_exists("mysql_real_escape_strin… ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue); switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? doubleval($theValue) : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue; } } $maxRows_Recordset1 = 3; $pageNum_Recordset1 = 0; if (isset($_GET['pageNum_Recordset1'])) { $pageNum_Recordset1 = $_GET['pageNum_Recordset1']; } $startRow_Recordset1 = $pageNum_Recordset1 * $maxRows_Recordset1; $colname_Recordset1 = "-1"; if (isset($_GET['title'])) { $colname_Recordset1 = $_GET['title']; } mysql_select_db($database_MyConnection… $MyConnection); $query_Recordset1 = sprintf("SELECT * FROM images2 WHERE key_words LIKE %s", GetSQLValueString("%" . $colname_Recordset1 . "%", "text")); $query_limit_Recordset1 = sprintf("%s LIMIT %d, %d", $query_Recordset1, $startRow_Recordset1, $maxRows_Recordset1); $Recordset1 = mysql_query($query_limit_Recordset1, $MyConnection) or die(mysql_error()); $row_Recordset1 = mysql_fetch_assoc($Recordset1); if (isset($_GET['totalRows_Recordset1'])) { $totalRows_Recordset1 = $_GET['totalRows_Recordset1']; } else { $all_Recordset1 = mysql_query($query_Recordset1); $totalRows_Recordset1 = mysql_num_rows($all_Recordset1); } $totalPages_Recordset1 = ceil($totalRows_Recordset1/$maxRows_Reco… ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-… <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> <table> <tr> <td></td> <td></td> <td></td> <td></td> </tr> <?php do { ?> <tr> <td><a href="viewimage.php?id=<?php echo $row_Recordset1['id']; ?>"><img src="<?php echo $row_Recordset1['Layouts']; ?>" width="300" height="250" /></a></td> <td width="300" height="250" align="center"><?php echo $row_Recordset1['Descriptions']; ?></td> </tr> <?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?> </table> </body> </html> <?php mysql_free_result($Recordset1); ?> Quote Link to comment Share on other sites More sharing options...
is_numeric Posted September 2, 2011 Report Share Posted September 2, 2011 This is Dreamweaver produced code. If we hack it then the risk is you wont be able to edit it in the DW panels and therefore put you in a worse position than you are in now Quote Link to comment Share on other sites More sharing options...
Jarel101 Posted September 3, 2011 Author Report Share Posted September 3, 2011 This is Dreamweaver produced code. If we hack it then the risk is you wont be able to edit it in the DW panels and therefore put you in a worse position than you are in now Just out of curiosity, how did you know it was DW produced code just by looking at it. Quote Link to comment Share on other sites More sharing options...
josephman1988 Posted September 8, 2011 Report Share Posted September 8, 2011 The first function is used by dreamweaver to protect from SQL injection, and the whole 'recordset' variables are produced only in dreamweaver. 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.
Note: Your post will require moderator approval before it will be visible.