justlukeyou Posted May 22, 2012 Author Share Posted May 22, 2012 Apologies, I thought you meant just the query. Okay, So I put the whole piece of code as below into MySQL and this is what it returned. This seems more useful? ERROR: Unknown Punctuation String @ 1 STR: <? SQL: <?php if (isset($_POST['keywords'])){ $keywords = mysql_real_escape_string (htmlentities(trim($_POST['keywords']))); SQL query: <?php if (isset($_POST['keywords'])){ $keywords = mysql_real_escape_string (htmlentities(trim($_POST['keywords']))); MySQL said: Documentation #1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '<?php if (isset($_POST['keywords'])){ $keywords = mysql_real_escape_string (htm' at line 1 <?php if (isset($_POST['keywords'])){ $keywords = mysql_real_escape_string (htmlentities(trim($_POST['keywords']))); } $errors = array(); $results = null; if (empty($keywords)) { $errors[] = 'Please enter a search term'; } else if (strlen($keywords)<3) { $errors[] = 'Your search must be three or more characters'; } else if (($results = search_results($keywords)) === false) { $errors[] = 'Your search for '.$keywords.' returned no results'; } if (empty($errors)) { foreach($errors as $error) { echo $error, '</br>'; } search_results ($keywords); } else{ foreach($errors as $error) { echo $error, '</br>'; } } ?> <?php function search_results ($keywords) { $returned_results = array(); $where = ""; $keywords = preg_split('/[\s]+/', $keywords); $total_keywords = count($keywords); foreach($keywords as $key=>$keyword) { $where .= "`keywords` LIKE '%$keyword%'"; if ($key != ($total_keywords - 1)) { $where .= " AND "; } } $results = "SELECT `description`, `fulldescription` FROM `productdbase` WHERE $where"; $results_num = ($results = mysql_query($results)) ? mysql_num_rows($results) : 0; if ($results_num === 0) { return false; }else{ echo 'something.'; } } ?> Link to comment https://forums.phpfreaks.com/topic/262881-double-running-query/page/2/#findComment-1347743 Share on other sites More sharing options...
Kays Posted May 22, 2012 Share Posted May 22, 2012 Right, you are confused. When I said execute (or run) the PHP file, I don't mean run it via MySQL. You may want to read a tutorial. Start here: http://devzone.zend.com/4/php-101-part-1-down-the-rabbit-hole/ Link to comment https://forums.phpfreaks.com/topic/262881-double-running-query/page/2/#findComment-1347756 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.