Forum Moderators: coopster

Message Too Old, No Replies

Send/insert data simultaneously

         

osemollie

9:22 am on Jan 30, 2006 (gmt 0)

10+ Year Member



I have the following code (patsted below)<code not necessary, removed>. My form is supposed to allow a user to choose at least two courses. When he clicks on the submit button, it should be able to send an email to the administrator indicating which courses have been selected and at the same time, the information keyed in the form should be captured into my mySQL. How can I implement that? Any ideas?

[edited by: coopster at 2:58 pm (utc) on Jan. 30, 2006]
[edit reason] Removed basic html form code [/edit]

grandpa

9:37 am on Jan 30, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Hi osemollie. You're new around here.. Welcome to WebmasterWorld.

You can gain a lot of knowledge in this Forum, and there are some basic guidelines [webmasterworld.com] that help us all.

To specifically address your question, have a look at the following thread from our Library [webmasterworld.com].
Basics of Submitting and Emailing Forms with PHP [webmasterworld.com]

omoutop

9:42 am on Jan 30, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Hi osemollie!

what you seek is very easy to implement, first of all you need to gather variables(data) submitted on the form and store them in the db, right after the 'storage' query (on the same script) and within your validation code (check if data inserted into DB) if data is inserted successfully send the e-mail using the exact same variables

Logic:

$query_store = "insert INTO courses (course_name, course code, student_id) VALUES ('".$_POST['course_name']."', ....., '".$_POST['student_id']."')";
$run_store = mysql_query($query_store) or die (mysql_error());
if (!run_store)
{
echo "error";
}
else
{
$to = 'someone@someone.com';

$subject = "blablabla $student_name in $course name.................";

$message ="Course subscription: $course_id\nStudent: $student_name\n...........";

mail($to, $subject, $message);
}
This code is pretty much what you need according to your problem (demo code though)

osemollie

1:09 pm on Jan 30, 2006 (gmt 0)

10+ Year Member



How do I store more than 2 checkbox data into mysql?

omoutop

1:29 pm on Jan 30, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Checkboxes are pretty much same as text boxes and they are stored in the DB in the same way, or syntax if you preffer. I would suggest you to read some of the basic mysql/php documentation in order to understand how this sotrage works. There are numerous tutorials on the net but in my opinion a good Book is the best start.

Hope the best