Jump to content

[SOLVED] simple IF question.. help needed.


grk101

Recommended Posts

how can i do this ..

 

in my html I have a search box and a drop down menu.

 

in my drop down i have three choices.  So you can search the main site, the sister site or others

 

<form id="form1" name="form1" method="post" action="post.php">
  <label>search
  <input type="text" name="search" id="search" />
<select name="">
   <option value="main">main site</option>
  <option value="sister">sister site</option>
<option value="other">other site</option>
</select>
</form>
</body>

 

Really, i just want a PHP code that will take the search term and redirect them to the proper page

 

So ,, IF "main" is selected from the drop down, redirect them to the main site passing the search variable

 

so

 

maybe like this?

 

$search = ($_POST['search']);
$main = ($_POST['main']);

if ($main 
header location(main.php?$search')

else
  echo "Make a selection!";

 

 

Can anyone help?

Link to comment
Share on other sites

<?php
$search = ($_POST['search']);
$san = ($_POST['san']);






if ($san)
{
header( "Location: http://yahoo.com" );



}
else
  echo "Have a nice day!";
?>

 

 

so i got that working, what i can't figure out is

 

how do i pass each individual value from the

 

<option select >

 

 

because the  <select name = "san"> it's only passing the "san" instead of the drop down choices.

 

i have given them values

 

any ideas?

 

Link to comment
Share on other sites


<form id="form1" name="form1" method="post" action="post.php">
  <label>search
  <input type="text" name="search" id="search" />
<select name="san">
   <option value="main">main site</option>
  <option value="sister">sister site</option>
<option value="other">other site</option>
</select>
</form>
</body>


 

the San is not passing any values of the drop down not sure why?

 

would i have to do the follwoing for each?

 

$main = ($_POST['main']);

Link to comment
Share on other sites

I just tried your from it works fine here.. try it out...

 

<?          
if($_POST["san"]){           
echo "You selected ".$_POST["san"];
}
?>
<form id="form1" name="form1" method="post" action="">
  <label>search
  <input type="text" name="search" id="search" />
<select name="san">
   <option value="main">main site</option>
  <option value="sister">sister site</option>
<option value="other">other site</option>
</select>
</form>
</body>

Link to comment
Share on other sites

thanks BK87 ,

 

that helped!

 

question

 

if i use header location to redirect to the search page

 

in the redirection url  lets say  http://www.yahoo.com can i use

 

the following:  http://www.yahoo.com/$search

 

Basically can i add the variable $search in the location header or do i have to use special quotes etc?

 

No quotes needed in header if theres already double quotes

 

	header("Location: yahoo.com/$search/title/$page");

Link to comment
Share on other sites

how many if statements like these can i use?

 

if ($san)

header( "Location: http://yahoo.com" );
exit;

if ($san)

header( "Location: http://google.com" );
exit;

 

I have four different URLS' but only the first IF statement works.

 

how can i get the others to work and redirect?

Link to comment
Share on other sites

The second won't work because the first one already directed the user to yahoo.com. You need some conditions.

 

Example:

 

<?
if ($san == "Dog")
{
// If the variable 'san' equals 'Dog', then you'll go to Yahoo.com
header("Location: http://yahoo.com");
}
if ($san == "Cat")
{
// If the variable 'san' equals 'Cat', then you'll go to Google.com
header("Location: http://google.com");
?>

 

In a way, you're confusing PHP. You have two identical IF statements that are BOTH possible, so it will just go with the first one by default.

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.