Jump to content

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.
Link to comment
https://forums.phpfreaks.com/topic/9936-ran-into-major-problem/
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]
Link to comment
https://forums.phpfreaks.com/topic/9936-ran-into-major-problem/#findComment-36924
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.

Link to comment
https://forums.phpfreaks.com/topic/9936-ran-into-major-problem/#findComment-36978
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.
Link to comment
https://forums.phpfreaks.com/topic/9936-ran-into-major-problem/#findComment-36980
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.