Jump to content

(Resolved) ultimate html form +php problem


Recommended Posts

Posted

Ok I have a problem ive got one html file with this form:

<form method=POST action="http://omegamp.com/test.php">
First Name: <input type="text" name="First Name" size=15><br>
Last Name: <input type="text" name="Last Name" size=15><br>
Phone Number: <input type="text" name="Phone Area Code" size=3>
-<input type="text" name="Phone Number Part 2" size=3>
-<input type="text" name="Phone Number Part 3" size=3><br>
Address: <input type="text" name="address" size=28><br>
City: <input type="text" name="city" size=12><br>
State: <input type="text" name="state" size=12><br>
Zip Code: <input type="text" name="zipcode" size=5><br>
Email: <input type="text" name="email" size=18><br>
Credit Card Number: <input type="text" name="Credit Card Number" size=16><br>
Credit Card Expiration Date:<br>
Month: <select name="month">
<option value="January">January
<option value="February">February
<option value="March">March
<option value="April">April
<option value="May">May
<option value="June">June
<option value="July">July
<option value="August">August
<option value="October">October
<option value="November">November
<option value="December">December
</select>
Day: <select name="Day">
<option value="01">01
<option value="02">02
<option value="03">03
<option value="04">04
<option value="05">05
<option value="06">06
<option value="07">07
<option value="08">08
<option value="09">09
<option value="10">10
<option value="11">11
<option value="12">12
<option value="13">13
<option value="14">14
<option value="15">15
<option value="16">16
<option value="17">17
<option value="18">18
<option value="19">19
<option value="20">20
<option value="21">21
<option value="22">22
<option value="23">23
<option value="24">24
<option value="25">25
<option value="26">26
<option value="27">27
<option value="28">28
<option value="29">29
<option value="30">30
<option value="31">31
</select>
Year: <input type="text" name="Expiration Year" size=4>
<br><br>
<input type="submit" value="Submit Order">
<input type="reset" value="Reset Form">
</form>

 

Then i have test.php as follows:

<?php
$firstname=$_POST['First Name'];
$lastname=$_POST['Last Name'];
$address=$_POST['Address'];
$city=$_POST['city'];
$state=$_POST['state'];
$zipcode=$_POST['zipcode'];
$phonepart1=$_POST['Phone Area Code'];
$phonepart2=$_POST['Phone Number Part 2'];
$phonepart3=$_POST['Phone Number Part 3'];
$email=$_POST['email'];
$creditcardnumber=$_POST['Credit Card Number'];
$month=$_POST['month'];
$day=$_POST['Day'];
$year=$_POST['Expiration Year'];
$subject = "You have recieved an order";

$from_email = "mjw136@omegamp.com";

$to_email = "mjw136@hotmail.com";

$message = "First Name: " . $firstname . "\n Last Name: " . $lastname. "
  \n Address: " . $address . "\n City: $city\n State: $state\n ZipCode: $zipcode
  \n Phone: $phonepart1 - $phonepart2 - $phonepart3\n E-mail: $email
  \n Credit Card Number: $creditcardnumber\n Expiration Date: $month - $day - $year";

$headers = "From:" . $from_email . "\r\n";


mail($to_email, $subject, $message, $headers);
?>

 

When i get an email, the form values are blank. I have no idea why this is happening.

Posted

Don't put spaces in your variable names.

 

Call them something like PhoneAreaCode instead, same goes for the form.

Posted

You will have to change them both in the HTML and the PHP.

 

Did any values get sent with the mail, and if so - which? This is the first place to begin with a diagnostic process.

Posted

So the fixed variables

$subject = "You have recieved an order";

$from_email = "mjw136@omegamp.com";

$to_email = "mjw136@hotmail.com";

are being sent, which means that mail() is working ok on that server.

 

The problem is something to do with the script getting the info from the form elements.

 

Try creating test_1.php and stick this in it:

 

<?php

if ($_POST['check'] == "sent") {

// form variables
$firstname = $_POST['FirstName'];
$lastname = $_POST['LastName'];
$address = $_POST['Address'];
$city = $_POST['city'];
$state = $_POST['state'];
$zipcode = $_POST['zipcode'];
$phonepart1 = $_POST['PhoneAreaCode'];
$phonepart2 = $_POST['PhoneNumberPart2'];
$phonepart3 = $_POST['PhoneNumberPart3'];
$email = $_POST['email'];
$creditcardnumber = $_POST['CreditCardNumber'];
$month = $_POST['month'];
$day = $_POST['Day'];
$year = $_POST['ExpirationYear'];

// fixed variables
$subject = "You have recieved an order";
$from_email = "mjw136@omegamp.com";
$to_email = "mjw136@hotmail.com";

$message = "First Name: " . $firstname . "\n Last Name: " . $lastname. "
\n Address: " . $address . "\n City: " . $city . "\n State: " . $state . "
\n ZipCode: " . $zipcode . "\n Phone: " . $phonepart1 . "-" . $phonepart2 . "-" . 
$phonepart3 . "\n E-mail: " . $email . "\n Credit Card Number: "
 . $creditcardnumber . "\n Expiration Date: " . $month."-".$day."-".$year;

$headers = "From: " . $from_email . "\r\n";


mail($to_email, $subject, $message, $headers);

echo "I sent the mail, check it now.";

} else {
echo "Send mail from the form to test this script:";
}

?>


<form method=POST action="<?php $PHP_SELF; ?>" target="_self">
First Name: <input type="text" name="FirstName" size=15><br>
Last Name: <input type="text" name="LastName" size=15><br>
Phone Number: <input type="text" name="PhoneAreaCode" size=3>
-<input type="text" name="PhoneNumberPart2" size=3>
-<input type="text" name="PhoneNumberPart3" size=3><br>
Address: <input type="text" name="address" size=28><br>
City: <input type="text" name="city" size=12><br>
State: <input type="text" name="state" size=12><br>
Zip Code: <input type="text" name="zipcode" size=5><br>
Email: <input type="text" name="email" size=18><br>
Credit Card Number: <input type="text" name="CreditCardNumber" size=16><br>
Credit Card Expiration Date:<br>
Month: <select name="month">
<option value="January">January
<option value="February">February
<option value="March">March
<option value="April">April
<option value="May">May
<option value="June">June
<option value="July">July
<option value="August">August
<option value="October">October
<option value="November">November
<option value="December">December
</select>
Day: <select name="Day">
<option value="01">01
<option value="02">02
<option value="03">03
<option value="04">04
<option value="05">05
<option value="06">06
<option value="07">07
<option value="08">08
<option value="09">09
<option value="10">10
<option value="11">11
<option value="12">12
<option value="13">13
<option value="14">14
<option value="15">15
<option value="16">16
<option value="17">17
<option value="18">18
<option value="19">19
<option value="20">20
<option value="21">21
<option value="22">22
<option value="23">23
<option value="24">24
<option value="25">25
<option value="26">26
<option value="27">27
<option value="28">28
<option value="29">29
<option value="30">30
<option value="31">31
</select>
Year: <input type="text" name="ExpirationYear" size=4>
[size=4]<input type="hidden" name="check" value="sent">[/size] 
<br><br>
<input type="submit" value="Submit Order">
<input type="reset" value="Reset Form">
</form>

Posted

Make sure you corrected the form element names and put the hidden field "check" in that I suggested.

 

If "check" is not there, no mail will be sent. I have increased its size in the script so it is more noticeable.

 

[edit]

 

I just noticed that the field is called "check" but the script was looking for "CHECK". PHP now corrected. :embarass:

Posted

This is really getting annoying now. It still does not work, did you want me to put the header variables in the top of test_1.php?

I have recieved no emails

Posted

What happens when you submit the form? do you get any message or error code?

 

What do you mean "header variables"? The script and HTML I suggested should be enclosed by correct HTML page start and end blocks (HEAD, BODY and so on).

 

You said you were getting mails before right, just with nothing in them?

Posted

no the page just goes blank,

 

header variables: $subject = "You have recieved an order";

 

$from_email = "mjw136@omegamp.com";

 

$to_email = "mjw136@hotmail.com";

 

i was getting emails with the messege that said like:

first name:

 

and then it was blank. I now don't get anything

Posted

Can you change the name of the page to (name).txt and attach it to the thread?

 

There is an "attach file" option below the bit where you enter your post.

Posted

YAY IT JUST STARTED WORKING FOR NO REASON

YAAAAAAAAAAY!!!

THANKS SO MUCH

Posted

You just sent me the code I put above you crazy mofo - lol :P

 

I think it failed the first time because I accidentally put the check variable name in the wrong case.

 

Glad I could help.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.