webguync Posted July 21, 2008 Share Posted July 21, 2008 I am trying to send form information to a database and also alert that the info has been sent to an email address. I know how to do one or the other, but didn't know if there was a way to do both at the same time? Quote Link to comment Share on other sites More sharing options...
jonsjava Posted July 21, 2008 Share Posted July 21, 2008 actually, it's quite simple. Post your code, and I'll set it up for you now. Quote Link to comment Share on other sites More sharing options...
webguync Posted July 21, 2008 Author Share Posted July 21, 2008 well here is the form code <html> <head> <title>Shadowmarket.com email form</title> <link rel="stylesheet" href="form.css" type="text/css" media="screen, handheld" /> </head> <body> <form action="formtoemailpro.php" method="post"> <fieldset> <legend></legend> <table cellspacing="5"> <tr><td><span class="asterisk">*</span><span class="small"> indicates a required field</td></tr> <tr><td><span class="asterisk">*</span> First Name:</td><td><input type="text" size="30" name="fname"></td></tr> <tr><td><span class="asterisk">*</span> Last Name:</td><td><input type="text" size="30" name="lname"></td></tr> <tr><td><span class="asterisk">*</span> Zip Code:</td><td><input type="text" size="30" name="zip"></td></tr> <tr><td><span class="asterisk">*</span> Login email:</td><td><input type="text" size="30" name="loginemail"></td></tr> <tr><td><span class="asterisk">*</span> Login Password:</td><td><input type="password" size="30" name="loginpw"></td></tr> <tr><td> Phone:</td><td><input type="text" size="30" name="phone"></td></tr> <tr><td> </td><td> <table border="0"> <tr><td colspan="3">Security test. Please identify the pictures:</td></tr> <tr><td><img src="images/identiPIC_1.jpg" alt=""></td><td><img src="images/identiPIC_2.jpg" alt=""></td><td><img src="images/identiPIC_3.jpg" alt=""></td></tr> <tr><td> <select name="identiPIC_selected[1]"> <option value="">Click to identify</option> <option>Apple</option> <option>Cat</option> <option>Clock</option> <option>Dog</option> <option>Flower</option> <option>Fork</option> <option>Hammer</option> <option>Key</option> <option>Ship</option> <option>Tree</option> </select></td><td> <select name="identiPIC_selected[2]"> <option value="">Click to identify</option> <option>Apple</option> <option>Cat</option> <option>Clock</option> <option>Dog</option> <option>Flower</option> <option>Fork</option> <option>Hammer</option> <option>Key</option> <option>Ship</option> <option>Tree</option> </select></td><td> <select name="identiPIC_selected[3]"> <option value="">Click to identify</option> <option>Apple</option> <option>Cat</option> <option>Clock</option> <option>Dog</option> <option>Flower</option> <option>Fork</option> <option>Hammer</option> <option>Key</option> <option>Ship</option> <option>Tree</option> </select></td></tr></table></td></tr> <tr><td> </td><td align="right"><input type="image" src="images/Send.jpg" value="Send"></td></tr> </table> </fieldset> </form> </body> </html> and the code to submit the information <?php //set up database and table names $db_name ="shadowdata"; $table_name ="RegistrationForm"; //connect to MySQL and select database to use $connection = @mysql_connect("localhost","username","password") or die(mysql_error()); $db = @mysql_select_db($db_name,$connection) or die(mysql_error()); //create SQL statement and issue query $sql = "INSERT INTO $table_name (fname, lname, zip, loginemail, loginpw, phone) VALUES ('$_POST[fname]', '$_POST[lname]', '$_POST[zip]', '$_POST[loginemail]', '$_POST[loginpw]', '$_POST[phone]')"; $result = @mysql_query($sql,$connection)or die(mysql_error()); $my_email = "reggie@shadowmarket.com"; $bcc = ""; $subject = "Comments from contact form"; ?> there is more code that I left out such as checking for required fields, but I thought you could use this to show me what needs to be done. Quote Link to comment Share on other sites More sharing options...
jonsjava Posted July 21, 2008 Share Posted July 21, 2008 I'd use this php code: <?php //set up database and table names $db_name ="shadowdata"; $table_name ="RegistrationForm"; //connect to MySQL and select database to use $connection = @mysql_connect("localhost","username","password") or die(mysql_error()); $db = @mysql_select_db($db_name,$connection) or die(mysql_error()); //create SQL statement and issue query $sql = "INSERT INTO $table_name (fname, lname, zip, loginemail, loginpw, phone) VALUES ('$_POST[fname]', '$_POST[lname]', '$_POST[zip]', '$_POST[loginemail]', '$_POST[loginpw]', '$_POST[phone]')"; $result = @mysql_query($sql,$connection)or die(mysql_error()); /* E-mail stuff here */ $my_email = "reggie@shadowmarket.com"; $bcc = ""; $subject = "Comments from contact form"; $message = "You received a mesage from {$_POST['loginemail']}"; //populate as you see fit from data from the form mail($my_email, $subject, $message); ?> or something like it. 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.