By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,871 Members | 2,444 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,871 IT Pros & Developers. It's quick & easy.

send message when keyword is submitted

P: 6
Heres what I'd like to accomplish and I believe I have to use server side script to do it.

I have a website where there is a question and then a text field below it to type in the answer to the question. When you click submit I'd first like it to tell the user if you submitted the correct answer, and second if the correct answer is submitted I'd like an email message to be sent to me letting me know the correct answer was submitted.
Dec 10 '07 #1
Share this Question
Share on Google+
3 Replies


Markus
Expert 5K+
P: 6,050
Hmm, there's many ways you can do it.

But you're not so clear on where you would like to head with this;

would you like, as soon as the button is clicked, an alert to say whether the correct keyword was typed? OR would you like to submit the information to another page (or the page it is typed into) and then compare the results?

The latter is better done with php/some server side scripting and the former (with alerts) would be best done with javascript.

If you could explain a little more, then i could give you extra tips.
Dec 10 '07 #2

P: 41
Heres what I'd like to accomplish and I believe I have to use server side script to do it.

I have a website where there is a question and then a text field below it to type in the answer to the question. When you click submit I'd first like it to tell the user if you submitted the correct answer, and second if the correct answer is submitted I'd like an email message to be sent to me letting me know the correct answer was submitted.
markus is right there are many ways to do this.

1. To do the validation of the question you do not need a server-side script, but you can use one if you want.

2. To send an e-mail you do.

The PHP could look something like this

[PHP]
<?php
session_start();

//I decided to user sessions to store the person who is going to answer
//the question, because I doubt you will want anonymous people
//spamming your mail box. I have a feeling that you want to restrict
//this to a few people.
$user = $_SESSION['user'];
$answer = "answer";

//check to see if the user actually submitted the answer
if (isset($_POST['answer'])) {
//INSERT some POST variable validation here
// or you can open yourself up to a lot of security vulnerabilities
if ($answer == $_POST['answer']) {
//send e-mail using mail function
//compile your e-mail message
$to = "youremail@example.com";
$subject = "Correct answer";
$message = "$_SESSION['user'] answered the question correctly";
mail($to, $subject, $message);
//set a message for your user to see
echo "Correct answer. Congratulations";
}
}
else {
echo "Incorrect answer. Please try again";
}


?>
[/PHP]

This is just the general idea, and you can make this as complicated or simple as you want.
Dec 10 '07 #3

P: 6
i'm sorry i wasnt so specific. I'd like to alert the user if they are correct as soon as submit is clicked.

maybe this will clear up some confusion:
The website is for my girlfriends christmas gift, theres a riddle to a location and she has to figure out the answer. I want to have a form where she types the answer and it tells her if its right or wrong, and when she types in the correct answer i want a message sent to my email letting me know she did. But the email message needs to be hidden because I dont want her to know it was sent.

I hope that makes more sense.
Thanks for your help.
Dec 11 '07 #4

Post your reply

Sign in to post your reply or Sign up for a free account.