Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Mar 2005
    Posts
    92
    Thanks
    0
    Thanked 0 Times in 0 Posts

    POST & GET question

    Hi and thx for a great forum!

    Im having some trouble with sending data from one page to another!

    I have a textfield and a submit-button. When clicking on the button the text in the textfield should be sent to another page where it is implemented into a search-function.

    Simple: I wan't the text in the textfield to be sent to another page. How is this easily done? I want the text to be saved in $sok which shall be used in this manner...

    PHP Code:
    $asking "SELECT namn, tillverkare, pris, vikt FROM artiklar WHERE namn = $sok"

  • #2
    Regular Coder
    Join Date
    Mar 2005
    Posts
    123
    Thanks
    0
    Thanked 0 Times in 0 Posts
    PHP Code:
    $sok $_POST['textfield_name']; 

  • #3
    New Coder
    Join Date
    Mar 2005
    Posts
    92
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Since I still don't clearly understand...here are some more code. Sorry to bother!

    PHP Code:
     <form name="form1" method="post" action="">
          <input name="searchfield" type="text" size="50" maxlength="30">
          <br>
          <input name="namn" type="radio" value="1">
           <span class="style2">Namn 
            <input name="vikt" type="radio" value="2"> 
            Vikt 
            <input name="tillverkare" type="radio" value="3"> 
            Tillverkare 
            <input name="pris" type="radio" value="4">
            Pris<br>
           </span><br>
          <input type="submit" name="Submit" value="S&ouml;k varor">
           <input name="clear" type="reset" id="clear" value="Rensa">    
                        </form>
    <?php
        
    include 'functions.php';
        if (isset(
    $namn)) {
    namn_search();
    }
    elseif (isset(
    $vikt)) {
    vikt_search();
    }
    elseif (isset(
    $tillverkare)) {
    tillverkare_search();
    }
    elseif (isset(
    $pris)) {
    pris_search();
    }
    else
        echo (
    "Välj ett alternativ ovan innan du söker.");
    ?>
    The textfield has the namne searchfield and when clicking on the button the text in that field should be usable in some functions on another page, functions.php.

    PHP Code:
    <?php
    function namn_search() {
    $sok $_GET['searchfield'];
    $db = @mysql_connect("localhost","root","")
            or die(
    "Kunde inte komma åt databasen!");
        
    $databasen mysql_select_db("matlistan");
        echo 
    "Alla varor i med<b></b>. Om ej vikt anges är priset ett kg-pris.";
        
    $asking "SELECT namn, tillverkare, pris, vikt FROM artiklar WHERE namn = $sok";
        
    $resultat mysql_query($asking);

        
    ?>
        <table borde="1" cellspacing="5" cellpadding="5" align="center">
            <tr>
                <th><?=mysql_field_name($resultat0);?></th>
                <th><?=mysql_field_name($resultat3);?></th>
                <th><?=mysql_field_name($resultat1);?></th>
                <th><?=mysql_field_name($resultat2);?></th>
            </tr>
        <?
        
    while ($raden mysql_fetch_row($resultat))
            echo 
    "<tr><td>$raden[0]</td><td>$raden[3]</td><td>$raden[1]</td><td>$raden[2]</td></tr>";
        
    ?>
        </table>    
        </td>
      </tr>
    </table>
    <?
    }
    ?>

  • #4
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,265
    Thanks
    6
    Thanked 48 Times in 48 Posts
    You're sending the form via POST, so

    $sok = $_GET['searchfield'];

    Won't work, it'll need to be

    $sok = $_POST['searchfield'];


    Also, you need to change

    if (isset($namn)) {

    to

    if (isset($_POST['namn'])) {

    Do the same with the rest

  • #5
    New Coder
    Join Date
    Mar 2005
    Posts
    92
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Excellent, that did the trick. Thank you very much for this.

    Best regards


  •  

    Posting Permissions

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