Broken Explode?

Post here is you are having problems with any of the tutorials.
Post Reply
Baz
Posts: 3
Joined: Sun Dec 11, 2011 1:42 pm

Broken Explode?

Post by Baz »

I have the following code from the database search tutorial and I seem to be getting empty arrays from it - Yet I can't see why!?
Any help would be great!
<?php 
function search_posts($term){
echo "keywords entered was $term<br/>";
	
	$keywords=explode(' ', mysql_real_escape_string($term));
	print_r($keywords);
	
}



?>

<form action="test.php" method="get">
          <input type="text" name="term"  /><br />
          <input type="submit" value="Search" />
        </form>
<?php 
  if(empty($_GET['term']) === false){
	search_posts($_GET['term']);
}
?>
Last edited by jacek on Sun Dec 11, 2011 2:08 pm, edited 1 time in total.
Reason: code tags...
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: Broken Explode?

Post by jacek »

Does the line
echo "keywords entered was $term<br/>";
Output what you expect ?

Also, you should really organise this code better, the function should be in a separate file and the processing code for the form should be at the top.
Image
Baz
Posts: 3
Joined: Sun Dec 11, 2011 1:42 pm

Re: Broken Explode?

Post by Baz »

well in the example video it splits the input placing them in an array starting at 0 and lists what it has placed where. My example only ever has 0 in its array and does not list what it is that it has found.

Seems the $term variable is found but some how it is getting lost in the explode part.

Any ideas what I have done wrong?
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: Broken Explode?

Post by jacek »

Is that the entire code, the only thing I can think of is that you are not connected to the database which would make mysql_real_escape_string return false and not the escaped string.
Image
Baz
Posts: 3
Joined: Sun Dec 11, 2011 1:42 pm

Re: Broken Explode?

Post by Baz »

Thank you for that it seems to of done the trick! 8-)

Hmmmmz odd indeed :roll:
Post Reply