hasek522 Posted August 12, 2008 Share Posted August 12, 2008 I am trying to use a FULLTEXT sql search but am encountering a sql error I cant figure out. Here is the error: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /nfs/c03/h01/mnt/48237/domains/hairneedhelp.net/html/search.php on line 15 Here is the code: $search = $_POST['search']; $search = '%' . $search . '%'; $db = mysql_connect($dbhost, $dbuser, $dbpassword); mysql_select_db($dbdatabase, $db); $search = mysql_real_escape_string($search); $sql = "SELECT * FROM stylists WHERE MATCH(firstname, lastname, city, salon, specialty) AGAINST ('" . $search . "');"; $query = mysql_query($sql); while($row = mysql_fetch_array($query)) Link to comment https://forums.phpfreaks.com/topic/119315-full-text-search/ Share on other sites More sharing options...
DarkWater Posted August 12, 2008 Share Posted August 12, 2008 You always need to do debugging and error checking on your queries in the development stage. Change: $query = mysql_query($sql); To: $query = mysql_query($sql) or die(mysql_error()); Link to comment https://forums.phpfreaks.com/topic/119315-full-text-search/#findComment-614623 Share on other sites More sharing options...
Jabop Posted August 12, 2008 Share Posted August 12, 2008 I would still include or die() in a production environment also Link to comment https://forums.phpfreaks.com/topic/119315-full-text-search/#findComment-614625 Share on other sites More sharing options...
DarkWater Posted August 12, 2008 Share Posted August 12, 2008 There are better ways to handle it at that level if you're making a serious application. If it's just a little PHP thing, then sure, you can keep the die clause in there. Link to comment https://forums.phpfreaks.com/topic/119315-full-text-search/#findComment-614630 Share on other sites More sharing options...
Jabop Posted August 12, 2008 Share Posted August 12, 2008 Example of a better method? Link to comment https://forums.phpfreaks.com/topic/119315-full-text-search/#findComment-614636 Share on other sites More sharing options...
DarkWater Posted August 12, 2008 Share Posted August 12, 2008 You would probably have exceptions set up for queries. Link to comment https://forums.phpfreaks.com/topic/119315-full-text-search/#findComment-614643 Share on other sites More sharing options...
discomatt Posted August 12, 2008 Share Posted August 12, 2008 Example of a better method? A proper error handling class. die()'ing is horrible. I'd rather purge all object buffers and output a decent looking error page, then die() silently. This allows you to hide details ( revealing potential database structure, ect ) in a production environment with a debug constant set to false, and allows you to see them while programming, or, debugging. Link to comment https://forums.phpfreaks.com/topic/119315-full-text-search/#findComment-614651 Share on other sites More sharing options...
DarkWater Posted August 12, 2008 Share Posted August 12, 2008 Precisely. die() is just plain ugly for production environments. Link to comment https://forums.phpfreaks.com/topic/119315-full-text-search/#findComment-614652 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.