Jump to content


Photo

ran into major problem


  • Please log in to reply
5 replies to this topic

#1 Ninjakreborn

Ninjakreborn
  • Members
  • PipPipPip
  • Information Technology Specialist
  • 3,922 posts
  • Age:33

Posted 18 May 2006 - 05:00 PM

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
<?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.");
}
}
?>
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
}if ($_POST['emailaddress'] !== $_POST['verifyemail']){
print("Unfortunately the email addresses did not match, please recheck what you put");
}else {
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.

------

Business Website: http://www.infotechnologist.biz

Personal Website: http://www.joyelpuryear.com

Blog Site: http://www.realmofwriting.com
Services: Web development, application development, mobile development, and custom development. All services listed on my website.


#2 alpine

alpine
  • Members
  • PipPipPip
  • Advanced Member
  • 756 posts
  • LocationNorway

Posted 18 May 2006 - 05:11 PM

You are doing a lot of if's with one else

try something like this
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
}


#3 Ninjakreborn

Ninjakreborn
  • Members
  • PipPipPip
  • Information Technology Specialist
  • 3,922 posts
  • Age:33

Posted 18 May 2006 - 05:30 PM

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.

------

Business Website: http://www.infotechnologist.biz

Personal Website: http://www.joyelpuryear.com

Blog Site: http://www.realmofwriting.com
Services: Web development, application development, mobile development, and custom development. All services listed on my website.


#4 otuatail

otuatail
  • Members
  • PipPipPip
  • Advanced Member
  • 960 posts

Posted 18 May 2006 - 07:15 PM

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.



#5 Ninjakreborn

Ninjakreborn
  • Members
  • PipPipPip
  • Information Technology Specialist
  • 3,922 posts
  • Age:33

Posted 18 May 2006 - 07:26 PM

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.

------

Business Website: http://www.infotechnologist.biz

Personal Website: http://www.joyelpuryear.com

Blog Site: http://www.realmofwriting.com
Services: Web development, application development, mobile development, and custom development. All services listed on my website.


#6 otuatail

otuatail
  • Members
  • PipPipPip
  • Advanced Member
  • 960 posts

Posted 18 May 2006 - 07:35 PM

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.






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users