Jump to content

Archived

This topic is now archived and is closed to further replies.

Ninjakreborn

ran into major problem

Recommended Posts

Sorry for yet another post, but I ran into a problem, that seems to be related to php. I don't understand this. Ok I have showed my form before, Here is my code
[code]
<?php
if ($_POST['firstname'] == ""){
print("Please go back and fill int he First Name field correctly<br />");
}if ($_POST['emailaddress'] == ""){
print("Please go back and fill in the Email Address field correctly<br />");
}if ($_POST['verifyemail'] == ""){
print("Please go back and fill in the Verify Email field correctly<br />");
}if ($_POST['description'] == ""){
print("Please go back and fill in the Description field correctly<br />");
}if ($_POST['emailaddress'] !== $_POST['verifyemail']){
print("Unfortunately the email addresses did not match, please recheck what you put");
}else {
$firstname = $_POST['firstname'];
$emailaddress = $_POST['emailaddress'];
$verifyemail = $_POST['verifyemail'];
$description = $_POST['description'];
$to = "businessman332211@hotmail.com";
$subject = "ideas and submissions";
$message = "
First Name: $firstname
Email Address: $emailaddress
Verify Email: $verifyemail
Description: $description
";

if(mail($to, $subject, $message)) {
print("Thank you for submitting your email has been successfully sent");
print("<br />Return to the homepage at <a href='http://www.freelancebusinessman.com'>Freelance Businessman</a>");
}else{
print("I am sorry but there was some sort of error and the email could not be sent");
print("<br />I am not totally sure of the cause of this error.");
print("<br />Please return to <a href='http://www.freelancebusinessman.com'>Freelance Businessman</a>");
print("<br />If you try again and recieve this error message a second time, then please email me at the original email address and notify me of this error, so it can be checked into.  Thank you for visiting Freelance Businessman.");
}
}
?>
[/code]
This is the problem. At first it wasn't sending the email, when I just had the email command in there, I got it working, then I incorporated the validation, and got it working, but it would validate it and send it anyway, then I formed the code as shown above, it worked, except for the last if statement, for instance, before it worked, but I added that last section
[code]
}if ($_POST['emailaddress'] !== $_POST['verifyemail']){
print("Unfortunately the email addresses did not match, please recheck what you put");
}else {
[/code]
when I added this last line of code it stopped working correctly and now again it started doing that, it started automatically sending the email and validating it at the same time, am I limited to how many if statements I can put before the else statement, or did I do it wrong somehow.

Share this post


Link to post
Share on other sites
You are doing a lot of if's with one else

try something like this
[code]
if (empty($_POST['firstname']))
{
print("Please go back and fill int he First Name field correctly<br />");
}
elseif (empty($_POST['emailaddress']))
{
print("Please go back and fill in the Email Address field correctly");
}
elseif (empty($_POST['verifyemail']))
{
print("Please go back and fill in the Verify Email field correctly<br />");
}
elseif (empty($_POST['description']))
{
print("Please go back and fill in the Description field correctly<br />");
}
elseif ($_POST['emailaddress'] !== $_POST['verifyemail'])
{
print("Unfortunately the email addresses did not match, please recheck what you put");
}
else
{
  // send
}
[/code]

Share this post


Link to post
Share on other sites
Thanks, that finally got everything working on that, and gave me something to look at in the future when I am doing things with these as well, thanks again for the help.

Share this post


Link to post
Share on other sites
I have used session variables to store all the fields entered with blank sessions variables obviously
where nothing is entered. re-directing back to the form populating the fields already entered. and turning
the text red or bold against the form entries that are blank and require filling in. ALSO a message at the top
explaing why.

I have had problems where the email has not been sent and it has been around the extra variable $headder

$success = mail($to,$sss, $mmm, $headers); where $header was
$headers = "From: $name <$from>\r\n";

also my Web hosting guy changed something on the server and I had to add a line above this

ini_set("sendmail_from", "root@des-otoole.co.uk");

But I have also been told not to rely on the return value of the mail() function.

Hope this helps.

P.S. Try doing this in Microsoft ASP. count the grey hairs.

Desmond.

Share this post


Link to post
Share on other sites
I'll take what you gave me and play around with it, see what I can come up with thanks. I don't know much asp, I am planning on only learning it enough to get by when a client needs something done. Php is my pride and joy, it's funner than any other server side languages I have played with. I have moved on now to trying to javascript validation, I am getting better at programming overall lately.

Share this post


Link to post
Share on other sites
Good LuclI am the otherway around ASP for years, but feeling very battered and brused with PHP although I have a C and C++ background. Same as PHP Semi's on ends of lines. Most C++ functions seem the same.

Good luck again. Des.

Share this post


Link to post
Share on other sites

×

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.