Page 1 of 2 12 LastLast
Results 1 to 10 of 13

Thread: Open new window URL, variable from form in URL PHP

  1. #1
    Join Date
    Dec 2008
    Posts
    22
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Open new window URL, variable from form in URL PHP

    Hi how are you?

    Code:
    <form name="form" target="_new" method="POST" action="mp3search.php">
    Song or Artist: <input name="mp3search" type="text" />
    <input type="submit" value="Search" />
    </form>
    This is a simple form. I want whatever the user entered in the text box to be concatenated into the URL in a new window when the user hits Submit:

    EX:
    This will open up as a new window showing google.com
    http://www.google.com/search?(VARIABLE)<--this is the variable from the textbox.

    so for example it would be: www.google.com/search?VARIABLE+fileextension

    best,
    Michael

  2. #2
    Join Date
    Sep 2008
    Location
    Bristol - UK
    Posts
    842
    Thanks
    32
    Thanked 132 Times in 131 Posts

    Default

    Hi there, to achieve this, you will need to be using the method="get", so that google can get the query from the url. Using post would result in the data not being sent through the url bar and so google wouldn't be able to produce a result.

    Here is the code:

    search.html

    Code:
    <html>
    
    <head>
    <title>Google Search</title>
    </head>
    
    <body>
    
    <form name="form" target="_new" method="get" action="mp3search.php">
    Song or Artist: <input name="mp3search" type="text" />
    <input type="submit" name="submit" value="Search" />
    </form>
    
    
    
    </body>
    
    </html>
    mp3search.php

    PHP Code:
    <?php

    if (isset($_GET['mp3search']))
    {
    $search $_GET['mp3search'];

    echo 
    "<meta http-equiv=\"Refresh\" content=\"0; url=http://www.google.com/search?q=" $search "\">";
    }
    else
    {
    echo 
    "You need to enter a search term";
    }

    ?>

  3. #3
    Join Date
    Dec 2008
    Posts
    22
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default

    http://img3.imageshack.us/img3/4231/36452236.jpg

    this is what i get for the outcome. it doesn't take me to google.com

    my firefox editor i think shows a break somewhere?

    thank you for your help on this.

  4. #4
    Join Date
    Sep 2008
    Location
    Bristol - UK
    Posts
    842
    Thanks
    32
    Thanked 132 Times in 131 Posts

    Default

    You're running the file straight from the source "C:/users/blabla". You need to either host it with your server provider or download WAMP (Windows only) or similar.

    Then execute the script through a local server. The reason it isn't working for you at the moment is because there is nothing there to interpret the PHP, just the HTML

  5. #5
    Join Date
    Dec 2008
    Posts
    22
    Thanks
    3
    Thanked 0 Times in 0 Posts

  6. #6
    Join Date
    Sep 2008
    Location
    Bristol - UK
    Posts
    842
    Thanks
    32
    Thanked 132 Times in 131 Posts

    Default

    Glad you got it working.

  7. #7
    Join Date
    Dec 2008
    Posts
    22
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default

    what is isset?

  8. #8
    Join Date
    Sep 2008
    Location
    Bristol - UK
    Posts
    842
    Thanks
    32
    Thanked 132 Times in 131 Posts

    Default

    isset

    That site's a great resource, just put any function you want into the search bar and it tells you how to use it

  9. #9
    Join Date
    Dec 2008
    Posts
    22
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default

    Hi Schmoopy,

    I put checkboxes in my form so users can choose what they want to search. How do I implement it so that if a user chooses the mp3 it will do the mp3 and if the user chooses MP3 WAV and WMA it goes in the URL and search those

    Code:
    echo "<meta http-equiv=\"Refresh\" content=\"0; url=http://www.google.com/search?hl=en&q=-inurl%3A(htm|html|php)+intitle%3A%22index+of%22+%2B%22last+modified%22+%2B%22parent+directory%22+%2Bdescription+%2Bsize+%2B(.mp3|.wma|.wav)+%22". $search ."%22\">";

    http://www.squaredvision.com/search/search.htm

    thank you,
    Michael

  10. #10
    Join Date
    Sep 2008
    Location
    Bristol - UK
    Posts
    842
    Thanks
    32
    Thanked 132 Times in 131 Posts

    Default

    Ok, so do you just want it to add the extension of the file?

    So if I searched for "Through the fire and the flames", it would add whatever button I checked to the end? Like "Through the fire and the flames.mp3"

    Tried and tested, but using checkboxes would be a little bit more complicated:

    PHP Code:
    <?php

    if(isset($_GET['extension']))
    {
    $extension "." $_GET['extension'];
    }
    else
    {
    die(
    "You need to select a format");
    }

    if (isset(
    $_GET['mp3search']) && $_GET['mp3search'] != "")
    {
    $search $_GET['mp3search'];

    echo 
    "<meta http-equiv=\"Refresh\" content=\"0; url=http://www.google.com/search?q=" $search $extension "\">";
    }
    else
    {
    die(
    "You need to enter a search term");
    }

    ?>
    I made the HTML into radio buttons to make it simpler:

    HTML Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <link rel="stylesheet" type="text/css" href="search.css">
    <title>G Search - by: Michael Fridman</title>
    </head>
    
    <body>
    
    <div id="content">
    
    <div class="searchMP3">
    <FIELDSET><LEGEND>Search for MP3s</LEGEND><br />
    <center><form name="form" target="_new" method="GET" action="Gsearch.php">
    
      Song or Artist:
      <input name="mp3search" type="text" />
      <input type="submit" value="Search" />
      <br />
      <br />
      <table width="296" border="0" cellpadding="0" cellspacing="0">
        <tr>
          <td width="70" height="20">
          <input name="extension" value="mp3" type="radio"  />
    
            .MP3 <br /></td>
          <td width="70"><input name="extension" value="wma" type="radio"  />
            .WMA</td>
          <td width="70"><input name="extension" value="wav" type="radio"  />
            .WAV</td>
          <td width="70"><input name="extension" value="ogg" type="radio"  />
            .OGG</td>
    
        </tr>
        <tr>
          <td colspan="5">&nbsp;</td>
        </tr>
      </table>
    </form>
    </center>
    </FIELDSET></div></div>
    </body>
    </html>

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •