Jump to content

Recommended Posts

I am trying to build a form so that a user can select a name, and send a message. The select option is pulling from a table in the db. When the form is posted the I have written an sql statement that will retrieve the email address according to the name selected. But I can't get it to work. Please help. When I echo sql it displays the statement with no value:

 

SELECT email_address FROM consultant WHERE con_id = ''

 

here is the code:

message.php

<?php
  require "dbconn2.php";

$sql="SELECT con_id, first_name FROM consultant";
  $result=mysql_query($sql);
  $rconsultant_option="";

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

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

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

<body>
<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']?>"><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>

</body>
</html>

messageconsultant.php

<?php

require "dbconn2.php";

  $email = $_POST['email'];
  $name = $_POST['name'];
  $body= $_POST['body'];
  $con_id = $_POST['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>

If anybody can help me it would be greatly appreciated.

Thanks and regs, 8)

Link to comment
https://forums.phpfreaks.com/topic/151732-solved-please-help/
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.