Jump to content

isset and switch case


swampone

Recommended Posts

i have a form that is a search field. When submitted it goes through a switch case statement. And if certain search words are entered a url for that case should be returned, but instead its using the default case url for every word entered in the search field. For example if a user enters amateur in the search field it goes to the default case. I know that the $searchTerm is making it through all the cases, because if you look at the default case it has $searchTerm in the url, and once form is submitted I can see the searchTerm in the url and the script is working properly. But it seems like its not stopping once it has a match with one of the cases.

if (isset($_GET['search'])){
	$searchTerm = isset($_GET['search']);
	switch ($searhTerm){

	case "":
		$url = "http://www.pornhub.com/video?o=mr&page=$page";
		break;
	case "amateur":
		$url = "http://www.pornhub.com/video?c=3&page=$page";
		break;
	case "anal":
		$url = "http://www.pornhub.com/video?c=35&page=$page";
		break;
               default:
		$url = "http://www.pornhub.com/video/search?search=$searchTerm&x=0&y=0&page=$page";
		break;
		}
}


Link to comment
Share on other sites

Replace these two lines

<?php
	$searchTerm = isset($_GET['search']);
	switch ($searhTerm){
?>

with

<?php
   switch ($_GET['search']) {
?>

 

You've already determined that it's set, so just use it.

 

Ken

Link to comment
Share on other sites

Wow!! That worked. You saved me so much time. I probably would been at it for hours trying to figure this out. After your explaination, I see what you are saying about anything entered returned true, but how you came up with

? $_GET['search'] : ''

Wow! I still have a lot to learn. Thanks a bunch.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.