Bicklo Posted June 18, 2017 Share Posted June 18, 2017 I am trying to get the tex value of the selected item in a drop down list but nothing seem to work. This is what I got so far. Can anyone guide me in the right direction? Thank you. <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" id="owner"> <?php $sql = mysql_query( "SELECT email FROM namen"); while ($row = mysql_fetch_array($sql)){ echo "<option value=\"owner1\">" . $row['email'] . "</option>"; } $owner = $_POST['owner']; ?> </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 $owner = $_POST['owner']; ////// here the problem ////// $myboxes = $_POST['comments']; echo $owner; ?> <div class="mailsend"> <div class="poper"><input type="submit" name="submit" value="Submit"></div> </div> </form> </div> And then <?php if(isset($_POST['submit'])){ $to = "me@mail.com"; // is replaced with my real email $from = $_POST['$owner']; // 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."; } ?> What do I mis or what is wrong. Quote Link to comment Share on other sites More sharing options...
Jacques1 Posted June 18, 2017 Share Posted June 18, 2017 You should look up how select elements actually function. It the code still “doesn't work”, you need to be more specific. We're not sitting in front of your screen. What I can tell you, though, is that your code is both hopelessly outdated and vulnerable. Look up PDO and PhpMailer as well. Quote Link to comment Share on other sites More sharing options...
gizmola Posted June 18, 2017 Share Posted June 18, 2017 $from = $_POST['$owner']; // this is the problem You are right about that. What it should be: $from = $_POST['owner']; Quote Link to comment Share on other sites More sharing options...
Bicklo Posted June 18, 2017 Author Share Posted June 18, 2017 Thank you for replying gentlemen. $_POST['owner'] seems to give me owner1 as value.... I have a look at it tomorrow. Quote Link to comment Share on other sites More sharing options...
Jacques1 Posted June 18, 2017 Share Posted June 18, 2017 Hence: You should look up how select elements actually function. Quote Link to comment Share on other sites More sharing options...
Bicklo Posted June 19, 2017 Author Share Posted June 19, 2017 You should look up how select elements actually function. I looked at that but don't really know what to make of it, my english is not that good. Quote Link to comment Share on other sites More sharing options...
Jacques1 Posted June 19, 2017 Share Posted June 19, 2017 My point is: The value you receive after the form has been submitted is determined by the value attribute of the option elements. Your options all have the same value, namely “owner1”, so that's obviously nonsense. You need to put the actual e-mail address into the value attribute. And don't forget to escape it. But PDO and PhpMailer are actually more important than your code problems. Quote Link to comment Share on other sites More sharing options...
Bicklo Posted June 19, 2017 Author Share Posted June 19, 2017 Thank you for replying, I can get the value with javascript <script> var e = document.getElementById("owner"); var strUser = e.options[e.selectedIndex].text; <?php $abc = "<script>document.write(strUser)</script>"?> </script> I have to find a way now to use $abc with $_POST(), no luck so far.. Somebody should have mentioned PDO and PhpMailer when I started this (small)project for a friend who is chairman of an association, I wiil have serious look at it before I start something new. Quote Link to comment Share on other sites More sharing options...
Jacques1 Posted June 19, 2017 Share Posted June 19, 2017 I can get the value with javascript. No, you cannot. You're grabbing the label, which is something entirely different. I've already explained that to you. I have to find a way now to use $abc with $_POST(), no luck so far.. I've just told you how it works in PHP. How difficult can it be to understand that the value attribute stands for the value? It literally says that. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.