KittyLou Posted September 18, 2007 Share Posted September 18, 2007 I'm fairly new to PHP so bear with me if I'm asking something really stupid. I'm trying to create a form with two drop down menus, (both populated from mysql databases). One of the databases has user names in it. The other has managers in it + their email addresses. The idea is that the user chooses their name and the name of the manager they will be working for and it then sends an email to the relevant manager telling them that the user's name and what time they have logged on. I've worked out how to populate the drop down menus from the database, and how to send the time and name via email. Unfortunately I haven't worked out how to tie them together or how to send to the different email addresses. I've been staring at the code so long it now looks like gibberish. Can anyone help me make sense of it? This is the code I'm using for my drop down menus (well, for the one with emails attached) <?php $hostname = "localhost"; $db_user = "db_user"; $db_password = "db_password"; $connect = mysql_connect($hostname, $db_user, $db_password) or die ("Could not connect to database."); mysql_select_db("projectmanager"); $query = mysql_query( "SELECT `pm_name` FROM `projectmanager`" ) or die (mysql_error()); echo "<select name='projectmanager'>\n"; while ($data1 = mysql_fetch_array($query, MYSQL_ASSOC)) { echo " <option value='{$data1['pm_name']}'> {$data1['pm_name']}</option>\n"; } echo "</select>\n"; ?> And this is the code I was using for the email, (obviously I need to change the $to option somehow) though it's currently not sending the PM name in the email. <? if($Submit){ $to="example@example.co.uk"; $subject="$pm_name - $Submit"; $time=date('F j, Y, H:i:s'); $message="$pm_name - $Submit - $time"; mail($to,$subject,$message,$mail_from); echo "<center><br /><br /><b>Your contact information has been sent</b></center>"; }else{ // Do following codes if not found "Submit" value.(Not submitted) ?> Any advice anyone? Edited to add: I did search for help with this (google etc) but could only find separate tutorials on populating drop downs and on sending to multiple addresses. And it seems I'm not quite clever enough to connect them Quote Link to comment Share on other sites More sharing options...
hackerkts Posted September 18, 2007 Share Posted September 18, 2007 Don't worry to ask questions if you're willing to learn(: Ok, let's get started. I assume you have already got the drop down menu and sending mails to different email address working. You can try to use the switch statement. Quote Link to comment Share on other sites More sharing options...
pikemsu28 Posted September 18, 2007 Share Posted September 18, 2007 this is what i would do..... if you populate the value of the drop down with the email addy of the managers 'value="{$data1['manager_email']}"' just submit your $_POST value to your email script and set the $to variable to the $_POST $to = $_POST['projectmanager']; Quote Link to comment Share on other sites More sharing options...
KittyLou Posted September 19, 2007 Author Share Posted September 19, 2007 Don't worry to ask questions if you're willing to learn(: Ok, let's get started. I assume you have already got the drop down menu and sending mails to different email address working. You can try to use the switch statement. I'm probably missing something really obvious, but I can't actually make sense of that page (I'm very glad I start a web design course on the 1st, things might make more sense then) I can't quite figure out how it'd relate to my drop down or my database. I get the feeling I'm going to be apologising for my lack of knowledge a lot on here pikemsu28> I've changed those bits of my code but I'm not receiving any emails, not getting any error messages either though Quote Link to comment Share on other sites More sharing options...
pikemsu28 Posted September 19, 2007 Share Posted September 19, 2007 make sure your query is pulling the manager's email addy from the database. $query = mysql_query("SELECT `pm_name`, `email field` FROM `projectmanager`") or die (mysql_error()); Quote Link to comment Share on other sites More sharing options...
KittyLou Posted September 19, 2007 Author Share Posted September 19, 2007 make sure your query is pulling the manager's email addy from the database. $query = mysql_query("SELECT `pm_name`, `email field` FROM `projectmanager`") or die (mysql_error()); Yep, done that, it's still refusing though :-\ Quote Link to comment Share on other sites More sharing options...
KittyLou Posted September 19, 2007 Author Share Posted September 19, 2007 No, sorry, I lie, it's working now. No idea why it didn't work earlier. The only problem I have now is that the email is arriving saying " - Log On - September 19, 2007, 15:48:55" When it's meant to say "User 1 - Log On - September 19, 2007, 15:48:55" The code for that bit is.. <?php $hostname = "localhost"; $db_user = "user"; $db_password = "password"; $db_table = "logon"; $connect = mysql_connect($hostname, $db_user, $db_password) or die ("Could not connect to database."); mysql_select_db("logon"); $query = mysql_query( "SELECT `user_name` FROM `logon`" ) or die (mysql_error()); echo "<select name='logon'>\n"; while ($name = mysql_fetch_array($query, MYSQL_ASSOC)) { echo " <option value='{$name['user_name']}'> {$name['user_name']}</option>\n"; } echo "</select>\n"; ?> Quote Link to comment Share on other sites More sharing options...
pikemsu28 Posted September 19, 2007 Share Posted September 19, 2007 lets see all of your code.... 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.