matt.sisto Posted March 30, 2009 Share Posted March 30, 2009 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, Quote Link to comment https://forums.phpfreaks.com/topic/151732-solved-please-help/ Share on other sites More sharing options...
JonnoTheDev Posted March 30, 2009 Share Posted March 30, 2009 You have no name for the select list value <select id="select1"> Should be ><select id="select1" name="con_id">< Then the selected value will be in: $_POST['con_id'] Quote Link to comment https://forums.phpfreaks.com/topic/151732-solved-please-help/#findComment-796767 Share on other sites More sharing options...
matt.sisto Posted March 30, 2009 Author Share Posted March 30, 2009 Thank you, I knew it would be something simple. Quote Link to comment https://forums.phpfreaks.com/topic/151732-solved-please-help/#findComment-796769 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.