Jump to content

[SOLVED] Using a dynamic dropdown as input


Hamish

Recommended Posts

Hi All,

 

This is my second attempt at using a MySQL generated query to populate a dropdown box to send email.

The query populates the dropdown box “ok”, allowing the desired email address to be selected. The problem seems to be in using this email address as the input. How do I get the selected email to then become an input?

 

Any ideas much appreciated.

 

Hamish

<?php

//Check whether the submission is made
if(isset($hidSubmit)){

//Declarate the necessary variables

$mail_to=$PLemailAddress;
$mail_from=$txtEmailfrm2;
$mail_sub=$txtSub2;
$mail_mesg=$txtMsg;


//Check for success/failure of delivery 

if(mail($mail_to,$mail_sub,$mail_mesg,"From:$mail_from Reply-to:$txtEmailfrm2"))
echo "<span class='textred'>E-mail has been sent successfully from $mail_sub to $mail_to</span>";
else
echo "<span class='textred'>Failed to send the E-mail from $mail_sub to $mail_to</span>";
}
?>
<!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=iso-8859-2" />
<title>php email</title>
</head>

<body>
<form name="frmsendmail" method="post" action="" onSubmit="return ValidationForm()">
  <table width="100%" border="0">
    <tr>
      <td><div align="right">To</div></td>
      <td><select name="PLemailAddress">
        <option>Please select a email from the list</option>
        <?php
include ("opendbincludeA.php");	
$query ="SELECT  P_Leader.PLemailAddress  FROM P_Leader"; 
$query = mysql_query($query);
$query_row=mysql_num_rows($query);


while ($row=mysql_fetch_array($query))
{	
	echo "<option value=".$row['PLemailAddress'].">".$row['PLemailAddress']."</option>";
}

?>
      </select></td>
    </tr>
    <tr>
      <td width="34%"><div align="right">From</div></td>
      <td width="66%"><input name="txtEmailfrm2" type="text" id="txtEmailfrm2" /></td>
    </tr>
    <tr>
      <td><div align="right">Subject</div></td>
      <td><input type="txtSub2" name="textfield" /></td>
    </tr>
    <tr>
      <td><div align="right">Message</div></td>
      <td><textarea name="txtMsg" cols="50" rows="6"></textarea></td>
    </tr>
    <tr>
      <td><div align="right"></div></td>
      <td><input type="submit" name="Submit" value="Submit" /></td>
    </tr>
  </table>

</form>


</body>

</html>

Link to comment
Share on other sites

Hi taith,

 

Thanks for the modified query which I have changed and tried, however when submitted the script does not get either success or failure from warnings nor is the email delivered.

 

Regards

 

Hamish

Link to comment
Share on other sites

Hi taith,

 

The dropdown populates with the result of the query in the form of an email address, ie fredblogs@pipex.net. You can select the an email address and it holds in the text box, allowing "from", "subject" and "message" to be filled in. Pressing submit gives the impression that the email has be forwarded and the form fields clear,  no error message but the email does not arrive.

I have tested the script without the dropdown and the emails arrive, the problem seems to be in getting from the dropdown to "input"

 

Regards

 

Hamish

Link to comment
Share on other sites

You are assuming register_globals is turned on, very bad and very insecure.

 

<?php

//Check whether the submission is made
if(isset($_POST['Submit'])){ // no hid I do not know where you got that from.

//Declarate the necessary variables

$mail_to=$_POST['PLemailAddress'];
$mail_from=$_POST['txtEmailfrm2'];
$mail_sub=$_POST['txtSub2'];
$mail_mesg=$_POST['txtMsg'];

 

That works with or without register_globals being on/off and you should generally use those anyways for security purposes.

 

$query=mysql_query("SELECT `PLemailAddress` FROM `P_Leader`") or die(mysql_error());

while($row=mysql_fetch_assoc($query)){

echo "<option>".$row['PLemailAddress']."</option>";

}

 

That is invalid code, the code you were using above should work just fine. If you want to try taith's code you need it to look like this instead

 

<?php
$query=mysql_query("SELECT `PLemailAddress` FROM `P_Leader`") or die(mysql_error());
while($row=mysql_fetch_assoc($query)){
echo "<option value=" . $row['PLemailAddress'] . ">".$row['PLemailAddress']."</option>";
}

 

The value part must be assigned.

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.