Results 1 to 6 of 6

Thread: Get value of selected in dropdown list

  1. #1
    Join Date
    Nov 2016
    Posts
    23
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Default Get value of selected in dropdown list

    I am trying to post the value of the selected in a dropdown list but no luck, can anyone help me please.


    PHP Code:
    <div class="mailvanform">

    <select id="owner">
    <?php
    $sql 
    mysql_query"SELECT email FROM namen");
    while (
    $row mysql_fetch_array($sql)){
    echo 
    "<option value=\"owner1\">" $row['email'] . "</option>";
    }

    echo = 
    $_POST['owner1'];


    ?>
    </select>


    </div>

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Is it a form? You cannot post without at least one of either:

    A.) A form submission under the method POST.

    Or:

    B.) An AJAX call via javascript, also under the method POST.

    I don't see either in your code snippet.

    A further potential issue I think see is that the value of all the options appears to be the same ("owner1").

    Now, I'm not even sure if you understand what $_POST is. It's an array of values that were posted to the PHP page/script. It will be an empty array if nothing has been posted. You cannot post to a page that's already loaded. And, unless you use javascript, you cannot get a value from a form or form element without submitting the form (which will reload the page or load some other resource). And, if using javascript alone to get the value, that value will be temporary unless it's sent to the server using AJAX in some fashion. Though you could get the value via javascript, and later the user could submit the form. If you know all that and just haven't shown those portions of the code, please include or explain it in detail it next time.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #3
    Join Date
    Nov 2016
    Posts
    23
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Default

    Thank you for your reply,

    It's a drop down list with items from a database, I want to send mail via php and it want work.

    So I try to find a way to achieve this.



    Code:
    <body>
        
    <div class="water">
        
    <form>  
    
    
    
    
    <!-- SELECT SENDER  -->
    
     
    <div class="mailtop">
    
    
    
    
    <div class="mailvan"><h1 class="hmailvan">Van:</h1></div>
    
    <div class="mailvanform">
        
    <select name="owner">
    <?php 
    $sql = mysql_query( "SELECT email FROM namen");
    while ($row = mysql_fetch_array($sql)){
    echo "<option value=\"owner1\">" . $row['email'] . "</option>";
    }
    ?>
    </select>    
        
        
        </div>
    
    </div>
    
    
    
    <!-- END SELECT SENDER  -->
    
    
    
    
    
    
    
    
    
    <!-- SELECT MAIL RECIPIENT  -->
    
    
    
    <div class="mailvoor"><div class="mailvoortitel"><h1 class="hmailvan">Aan:</h1></div>
    
    <div class="mailvoorform">
    
      <?php
    if(isset($_POST['lombi'])){
        
    $mailvoor = $_POST['lombi'];    
     
    }
    
    if(isset($_POST['variable'])){
        
        $mailonderwerp = $_POST['variable'];
        
     
        
        
      $eind1= mysql_query("SELECT e1 FROM items WHERE item='$mailonderwerp'");
     
     while ($row = mysql_fetch_object($eind1)){   
        
        $titel1=$row->e1;
         
         
         };
        
     $mails1= mysql_query("SELECT email FROM namen WHERE titel='$titel1'");   
        
      while ($row = mysql_fetch_object($mails1)){   
        
        echo $row->email.' ; ';
         
         
         };
        
        
        
      $eind2= mysql_query("SELECT e2 FROM items WHERE item='$mailonderwerp'");
     
     while ($row = mysql_fetch_object($eind2)){   
        
        $titel2=$row->e2;
         
         
         };
        
     $mails2= mysql_query("SELECT email FROM namen WHERE titel='$titel2'");   
        
      while ($row = mysql_fetch_object($mails2)){   
        
        echo $row->email.' ; ';
         
         
         };    
        
        
        
        
       }    
    
         
        
    $vtest = mysql_query("SELECT d1, d2, d3 FROM items WHERE item='$mailonderwerp'");
        
        
    
    
    while ($row = mysql_fetch_array($vtest)){
        $doen1 = $row['d1']; 
        $doen2 = $row['d2'];
        $doen3 = $row['d3'];
        
    
    }
        
    
    if ($doen1 !=NULL){   
    $xtest = mysql_query("SELECT email FROM namen Where titel ='$doen1''");
        
        
    
    
    while ($row = mysql_fetch_object($xtest)){
      echo '<p><a href=""><div class="namen">'.$row->email.'</div></a></p>'; 
        
       
    
    }
    }    
        
       
    
    
    
    if ($doen2 !=NULL){
        
        
    $ytest = mysql_query("SELECT * FROM $doen2");
        
        
    
    
    while ($row = mysql_fetch_object($ytest)){
      echo '<p><a href=""><div class="namen">'.$row->naam.'</div></a></p>'; 
        
       
    }
    }
        
        
       
    
    if ($doen3 !=NULL){
        
        
    $ztest = mysql_query("SELECT * FROM $doen3");
        
        
    
    
    while ($row = mysql_fetch_object($ztest)){
      echo '<p><a href=""><div class="namen">'.$row->naam.'</div></a></p>'; 
        
       
    }
    
    }
        
    
    ?>    
        
    
    
    
    </div>
    
    
    
    
    </div> 
    
    
    <!-- END SELECT MAIL RECIPIENT  -->
    
    
    
    
    
    
    
    
    <!-- MAIL SUBJECT -->
    
    
    <div class="mailtitel">
    
    
    
    <div class="mailtiteltitel"><h1 class="hmailvan">Onderwerp:</h1></div> 
    
    
    <div class="mailtitelform">
    
      <?php
    if(isset($_POST['variable'])){
        echo 'Edri '.$_POST['variable'];
    }
    
    ?>
    </div>
    
    
    </div> 
    
    
    <!-- END MAIL SUBJECT -->
    
    
    
    
    
    
    <!-- MAIL TITLE -->
    
    
    <div class="mailbericht">
    
    <div class="mailberichttitel"><h1 class="hmailvan">Bericht:</h1></div>
        
        <div class="mailberichttitelform">
    	
    	<textarea class="comment" name="comments"></textarea>
    	
    	
    	</div>   
    
    </div> 
    
    
    
    <!-- END MAIL TITLE -->
    
       
    
    <div class="mailsend">
    
    <div class="poper"><input type="submit" value="versturen"></div>
    
    </div> 
         
    
     </form> 
    
    
           
    </div> 
         
       
         
     </body>

  4. #4
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    OK, hmm. There're no action or method attributes to the form. The action attribute will tell it what PHP script to or page to goto/run when it's submitted, and the method attribute will tell it how to send (GET or POST) the form data to that PHP page/script. I see no javascript, so I'm guessing that's not part of what you want to do. The page can submit to itself, this is often done, and then based upon whether or not certain POST or GET data is present it can do different things. Still, the most common practice is to submit to a separate script or page.

    I hope that helps you get on track. I will have a closer look at your code and this thread though to see if I can figure out what you're intending to do, and if possible give more concrete suggestions.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  5. #5
    Join Date
    Nov 2016
    Posts
    23
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Default

    So far I have this,

    Code:
    <body>
        
    <div class="water">
    
    
    <form action="mail_handler.php" method="post">   
    
    <div class="mailtop">
    
    
     
    
    
    <div class="mailvan"><h1 class="hmailvan">Van:</h1></div>
    
    <div class="mailvanform">
        
    <select name="owner">
    <?php 
    $sql = mysql_query( "SELECT email FROM namen");
    while ($row = mysql_fetch_array($sql)){
    echo "<option value=\"owner1\">" . $row['email'] . "</option>";
    
    $van = "<option value=\"owner1\">" . $row['email'] . "</option>";        // here  the problem, get the email address from a  drop down list 
    
    $lopen = $_POST['$van'];
    
    }
    ?>
    </select>    
        
        
        </div>
    
    </div>
    
    
    
    <div class="mailvoor"><div class="mailvoortitel"><h1 class="hmailvan">Aan:</h1></div>
    
    <div class="mailvoorform">
    
      <?php
    if(isset($_POST['lombi'])){
        
    $mailvoor = $_POST['lombi'];    
     
    }
    
    if(isset($_POST['variable'])){
        
        $mailonderwerp = $_POST['variable'];
        
     
        
        
      $eind1= mysql_query("SELECT e1 FROM items WHERE item='$mailonderwerp'");
     
     while ($row = mysql_fetch_object($eind1)){   
        
        $titel1=$row->e1;
         
         
         };
        
     $mails1= mysql_query("SELECT email FROM namen WHERE titel='$titel1'");   
        
      while ($row = mysql_fetch_object($mails1)){   
        
        echo $row->email.' ; ';
         
         
         };
        
        
        
      $eind2= mysql_query("SELECT e2 FROM items WHERE item='$mailonderwerp'");
     
     while ($row = mysql_fetch_object($eind2)){   
        
        $titel2=$row->e2;
         
         
         };
        
     $mails2= mysql_query("SELECT email FROM namen WHERE titel='$titel2'");   
        
      while ($row = mysql_fetch_object($mails2)){   
        
        echo $row->email.' ; ';
         
         
         };    
        
        
        
        
       }    
    
         
        
    $vtest = mysql_query("SELECT d1, d2, d3 FROM items WHERE item='$mailonderwerp'");
        
        
    
    
    while ($row = mysql_fetch_array($vtest)){
        $doen1 = $row['d1']; 
        $doen2 = $row['d2'];
        $doen3 = $row['d3'];
        
    
    }
        
    
    if ($doen1 !=NULL){   
    $xtest = mysql_query("SELECT email FROM namen Where titel ='$doen1''");
        
        
    
    
    while ($row = mysql_fetch_object($xtest)){
      echo '<p><a href=""><div class="namen">'.$row->email.'</div></a></p>'; 
        
       
    
    }
    }    
        
       
    
    
    
    if ($doen2 !=NULL){
        
        
    $ytest = mysql_query("SELECT * FROM $doen2");
        
        
    
    
    while ($row = mysql_fetch_object($ytest)){
      echo '<p><a href=""><div class="namen">'.$row->naam.'</div></a></p>'; 
        
       
    }
    }
        
        
       
    
    if ($doen3 !=NULL){
        
        
    $ztest = mysql_query("SELECT * FROM $doen3");
        
        
    
    
    while ($row = mysql_fetch_object($ztest)){
      echo '<p><a href=""><div class="namen">'.$row->naam.'</div></a></p>'; 
        
       
    }
    
    }
        
    
    ?>    
        
    
    
    
    </div>
    
    
    
    
    </div> 
    
    <div class="mailtitel">
    
    
    <div class="mailtiteltitel"><h1 class="hmailvan">Onderwerp:</h1></div> 
    
    
    <div class="mailtitelform">
    
      <?php
    if(isset($_POST['variable'])){
        echo 'DERI '.$_POST['variable'];
    }
    
    ?>
    </div>
    
    
    </div> 
    
    
    <div class="mailbericht">
    
    <div class="mailberichttitel"><h1 class="hmailvan">Bericht:</h1></div>
        
        <div class="mailberichttitelform">
    	
    	
    	<textarea class="comment" name="comments">
    	
    	
    	
    	
    	</textarea>
    	
    	
    	</div>   
    
    </div> 
    
    
    <?php
    
    $myboxes = $_POST['comments'];                 // this works ok
    
    ?>
       
    
    <div class="mailsend">
    
    <div class="poper"><input type="submit" name="submit" value="Submit"></div>
    
    
    </div> 
         
    
     </form> 
    
    
           
    </div> 
         
       
         
     </body>

    and a event handler like this,

    Code:
    <?php
    if(isset($_POST['submit'])){
        $to = "my.email@host.com"; // is replaced with my real email 
        $from = $_POST[$van]; // this is the problem
        $first_name = $_POST['first_name'];
        $last_name = $_POST['last_name'];
        $subject = "DERI";
        $subject2 = "Copy of your form submission";
    
        $message = $from . " schreef volgend bericht:" . "\n\n" . $_POST['comments'];
    
    
        $headers = "From:" . $from;
    
        mail($to,$subject,$message,$headers);
    
        echo "Mail werd met succes verstuurd.";
      
        }
    ?>
    Trying for 2 days now but no luck.

  6. #6
    Join Date
    Nov 2016
    Posts
    23
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Default

    The drop-down list is a list of email addresses from a database, so what i want is to echo or $_POST the selected email address on submit.

    Hope to be a little clearer.

Similar Threads

  1. Replies: 0
    Last Post: 01-28-2011, 07:53 PM
  2. Replies: 1
    Last Post: 03-20-2009, 10:47 AM
  3. Replies: 1
    Last Post: 10-18-2008, 12:31 PM
  4. Dropdown list showing above Dropdown/Overlapping Content Script in IE6/Win
    By captcashew in forum Dynamic Drive scripts help
    Replies: 0
    Last Post: 05-17-2007, 03:36 PM
  5. Hide list item when another is selected
    By billyboy in forum JavaScript
    Replies: 2
    Last Post: 11-28-2006, 06:01 PM

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
  •