PDA

View Full Version : Desperate need of help, if else statements,



webbcreative
July 23rd, 2007, 11:41 PM
I am a total beginner, so i have downloaded this php file from Kirupa. and i cant get it to work with my site.

everytime i hit submit i got the error message -"blarg"
but recently it doesnt give me a confirmation or an error, just a blank page....

i dont know where the problem is if anyone could help it would be greatly appreciated.
i have 6 selections that have drop down menus, not sure if those are done correctly...

and i know the foreach isnt correct, i have been grasping at straws on that one.


<?php
if(isset($_POST['submit'])) {

$to = "chris@tatepublishing.com";
$subject = "Narration Selection from $name";
$name_field = $_POST['name'];
$email_field = $_POST['email'];
$book_field = $_POST['book'];
$words_field = $_POST['words'];
$option = $_POST['radio'];
$josh = $_POST['drop_down'];
$thomas = $_POST['drop_down'];
$rachael = $_POST['drop_down'];
$eva = $_POST['drop_down'];
$mike = $_POST['drop_down'];
$melissa = $_POST['drop_down'];
$main_field = $_POST['main'];
$other_field = $_POST['other'];
$special_field = $_POST['special'];

foreach($_POST['drop_down'] as $value) {
$check_msg .= "drop_down: $value\n";
}


$body = "From: $name_field\n eMail: $email_field\n Option: $option\n Drop-Down: $dropdown\n josh: $josh\n thomas: $thomas\n rachael: $rachel\n eva: $eva\n mike: $mike\n melissa: $melissa\n
main: $main_field\n other: $other_field\n special: $special_field\n";

echo "Congratulations $name_field!";
mail($to, $subject, $body);

} else {
echo "blarg!";
}
?>

icio
July 24th, 2007, 02:16 AM
Can we see the HTML for the form that you're using to submit to this page? I think this is where the error lies.

kwing
July 24th, 2007, 03:18 AM
Try adding some display messages at one of the lines, like echo "passed to this point", at that way, you'll notice where you got an error.

cheers
:)

Refined
July 24th, 2007, 01:01 PM
Hi webbcreative,

First, make sure your HTML method attribute is set to 'post'.

I'm assuming $_POST['drop_down'] is a <select> element on the form? You've got lots of $name = $_POST['drop_down'] mappings, all this is doing is making each of those name variables the same value: The selected value from the 'drop_down' <select> element.

If however this is a multiple select element, make sure the name of it is drop_down[] so that when multiple options are selected, they become an array on the server side.

EG


<select name="drop_down[]">In PHP you can then do:



<?php
foreach ($_POST['drop_down'] as $option)
{
// process...
}
?>
Also, in your foreach statement, you've got:



$check_msg .= "drop_down: $value\n";
But $check_msg hasn't been defined as a variable yet, put $check_msg = ''; before the foreach statement. This should throw an error but I guess they've disabled error outputting on your server.

Hope that helps.