Jump to content

Recommended Posts

Hello I am trying to build a form that the cleint can select a name from a drop down list which is pulling it from a table in the database, and send them an email. I haven't got that far yet. I am still trying to get the form working. I have the drpodown lst working, but when the form is submitted, I have written some script to extract the email address from the table where the ids match., however when I echo the sql, it is not receiving the id from the form, its just blank. I am sure its is quite simple but because its not a particularly complicated form but I could do with some help.

 

message.php

<?php
  require "dbconn2.php";
//code used to generate the select options
$sql="SELECT con_id, first_name FROM consultant";
  $result=mysql_query($sql);
  $rconsultant_option="";

while ($row=mysql_fetch_array($result)) {

    $id=$row["con_id"];
    $first_name=$row["first_name"];
    $consultant_option.="<OPTION VALUE=\"$id\">".$first_name;
}

?>
//form

<html>
<form name="messageConsultant" action="messageconsultant.php" method="post">
<label id="label1"> Your Email Address:</label> <input id="input1" type="text" name="email" value="<?=$row['email']?>" enctype="application/x-www-form-urlencoded"><p></p>
<label id="label2">Your Name:</label><input id="input2" type="text" name="name" value="<?=$row['name']?>">
<label id="label3">Consultants Name:</label><select id="select1"><option value="<?=$row['first_name']?>">Choose <?=$consultant_option?>
</option></select>
<label id="label4">Message Content:</label><textarea id="input5" name="body" value="<?=$row['body']?>"></textarea>
<input id="input6" type="submit" value="send" />
</form>
</html>
[code]

messageconsultant.php:
[code]
<?php

require "dbconn2.php";

  $email = $_GET['email'];
  $name = $_GET['name'];
  $body= $_GET['body'];
  $con_id = $_GET['first_name'];

  $sql = "SELECT email_address FROM consultant WHERE con_id = '$con_id'";	
  $result=mysql_query($sql);
  echo $sql;

?>

<!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" />
<title>?Message Consultant</title>
</head>

<body>
</body>
</html>

Apprecate any help. 8)

Link to comment
https://forums.phpfreaks.com/topic/151723-email-form/
Share on other sites

first when collecting information from a form you dont use $_GET, you use $_POST

 

so your code will be

 

$email = $_POST["email"]; etc

 

so $con_id = $_POST["first_name"];

 

and the parts inbetween the [""] are the fieldnames from the form so for your dropdown list

 

<select name="first_name">

<option>fred</option>

<option>jason</option>

</select>

 

then the variable $con_id would pick up fred or jason which ever was slected

 

hope that helps

 

Alex

 

Link to comment
https://forums.phpfreaks.com/topic/151723-email-form/#findComment-796772
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.