Jump to content

[SOLVED] PHP code has me somewhat stumped


ornclo

Form keeps erroring out. Help figuring out why.  

2 members have voted

  1. 1. Form keeps erroring out. Help figuring out why.

    • Error Issue
      1
    • Missing PHP Code
      1


Recommended Posts

To Whome May know more about PHP than I...

 

I will be the first to tell you that I get frustrated with PHP (at the moment) because I don't know everything there is to know about it, and I haven't had a chance to really work with it.  I am on a time line with a web page that I am creating for my church.  I am no Web Master, and a lot of what I have learned is self - taught or looking online to find my answer.  This one seems to be a bit more tricky to solve for me.  I always seems to simple when I go online, but it never works.  So here is my situation.

 

I have a form that I have created that has text fields, radio buttons, and check boxes in it.  I have created the php code for this as well.  When I hit submit, all I get is my error.html page saying that something in the form is incorrect.  So all I asking if someone would be kind enough to look over the code and let me know what I need to do to make it work.  Also, ANY additional information that you can give me, would be fantastic.  I want to learn more about PHP and how it works and ways to make it simpler. 

 

Here is the form:

http://www.achurch4life.net/WUcontact.html

 

Here is my code for the php file:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"

"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

 

<html xmlns="http://www.w3.org/1999/xhtml">

 

<head>

 

  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

 

  <title>Emailing Form Data</title>

 

</head>

 

<body>

 

<?php

 

  //declaration of variables

 

  $EmailFrom = Trim(stripslashes($_POST['EmailFrom']));

  $EmailTo =  "ornclo@aol.com,ornclo@aol.com";

  $Subject =  "Women United Contact";

 

  $Name =    Trim(stripslashes($_POST['name']));

  $Address =  Trim(stripslashes($_POST['address']));

  $City =    Trim(stripslashes($_POST['city']));

  $State =    Trim(stripslashes($_POST['state']));

  $Phone1 =  Trim(stripslashes($_POST['phone1']));

  $Phone2 =  Trim(stripslashes($_POST['phone2']));

  $Phone3 =  Trim(stripslashes($_POST['phone3']));

 

  $Church =  Trim(stripslashes($_POST['visit']));

  $About =    Trim(stripslashes($_POST['hear']));

  $Ask =      Trim(stripslashes($_POST['help']));

 

  $Comments = Trim(stripslashes($_POST['comments']));

 

 

  // validation

 

  $validationOK=true;

 

  if (Trim($EmailFrom)=="") $validationOK=false;

  if (Trim($Name)=="")      $validationOK=false;

  if (Trim($Address)=="")  $validationOK=false;

  if (Trim($City)=="")      $validationOK=false;

  if (Trim($State)=="")    $validationOK=false;

  if (Trim($Phone1)=="")    $validationOK=false;

  if (Trim($Phone2)=="")    $validationOK=false;

  if (Trim($Phone3)=="")    $validationOK=false;

 

  if (Trim($Comments)=="")  $validationOK=false;

 

  if (!$validationOK) {

    print "<meta http-equiv=\"refresh\" content=\"0;URL=WUerror.html\">";

    exit;

  }

 

 

  // prepare email body text

 

  $Body .= "";

  $Body .= "Name: ";

  $Body .= $Name;

  $Body .= "\n";

  $Body .= "Address: ";

  $Body .= $Address;

  $Body .= "\n";

  $Body .= "City: ";

  $Body .= $City;

  $Body .= "\n";

  $Body .= "State: ";

  $Body .= $State;

  $Body .= "\n";

  $Body .= "Phone: ";

  $Body .= $Phone1;

  $Body .= "-";

  $Body .= $Phone2;

  $Body .= "-";

  $Body .= $Phone3;

  $Body .= "\n";

  $Body .= "Attended Church?: ";

  $Body .= $Church;

  $Body .= "\n";

  $Body .= "How did they hear about us?: ";

  $Body .= $About;

  $Body .= "\n";

  $Body .= "What would you like us to do for you?: ";

  $Body .= $Ask;

  $Body .= "\n";

  $Body .= "Email: ";

  $Body .= $EmailFrom;

  $Body .= "\n";

  $Body .= "Comments: ";

  $Body .= $Comments;

  $Body .= "\n";

 

 

  // send email

 

  $success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");

 

 

  // redirect to success page

 

  if ($success){

    print "<meta http-equiv=\"refresh\" content=\"0;URL=WUok.html\">";

  }

  else{

    print "<meta http-equiv=\"refresh\" content=\"0;URL=Wuerror.html\">";

  }

 

  php?>

 

</body>

 

</html>

 

 

Again, any and all help would be greatly appreciated.

 

Thank you in advance.

 

Christopher

Link to comment
Share on other sites

Thank you to both.

I have fixed the code.

That wasn't the issue.

 

The "error code" is my own error.html screen that comes up.

In other words, it doesn't send the form to my email like it is suppost to.

 

Where do I put the


part?  Or which part are you referring to?

 

I will put that error test code you mentioned in.

 

Link to comment
Share on other sites


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>
   
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  
  <title>Emailing Form Data</title>
  
</head>

<body>

<?php 
   
  ini_set ("display_errors", "1");
  error_reporting(E_ALL);

  //declaration of variables

  $EmailFrom = Trim(stripslashes($_POST['EmailFrom'])); 
  $EmailTo =   "ornclo@aol.com,ornclo@aol.com";
  $Subject =   "Women United Contact";
  
  $Name =     Trim(stripslashes($_POST['name']));
  $Address =  Trim(stripslashes($_POST['address']));
  $City =     Trim(stripslashes($_POST['city']));
  $State =    Trim(stripslashes($_POST['state']));
  $Phone1 =   Trim(stripslashes($_POST['phone1']));
  $Phone2 =   Trim(stripslashes($_POST['phone2']));
  $Phone3 =   Trim(stripslashes($_POST['phone3']));
  
  $Church =   Trim(stripslashes($_POST['visit']));
  $About =    Trim(stripslashes($_POST['hear']));
  $Ask =      Trim(stripslashes($_POST['help']));

  $Comments = Trim(stripslashes($_POST['comments'])); 


  // validation

  $validationOK=true;

   if (Trim($EmailFrom)=="") $validationOK=false;
   if (Trim($Name)=="")      $validationOK=false;
   if (Trim($Address)=="")   $validationOK=false;
   if (Trim($City)=="")      $validationOK=false;
   if (Trim($State)=="")     $validationOK=false;
   if (Trim($Phone1)=="")    $validationOK=false;
   if (Trim($Phone2)=="")    $validationOK=false;
   if (Trim($Phone3)=="")    $validationOK=false;

   if (Trim($Comments)=="")  $validationOK=false;
   
   if (!$validationOK) {
    print "<meta http-equiv=\"refresh\" content=\"0;URL=WUerror.html\">";
    exit;
   }


   // prepare email body text

   $Body .= "";
   $Body .= "Name: ";
   $Body .= $Name;
   $Body .= "\n";
   $Body .= "Address: ";
   $Body .= $Address;
   $Body .= "\n";
   $Body .= "City: ";
   $Body .= $City;
   $Body .= "\n";
   $Body .= "State: ";
   $Body .= $State;
   $Body .= "\n";
   $Body .= "Phone: ";
   $Body .= $Phone1;
   $Body .= "-";
   $Body .= $Phone2;
   $Body .= "-";
   $Body .= $Phone3;
   $Body .= "\n";
   $Body .= "Attended Church of God?: ";
   $Body .= $Church;
   $Body .= "\n";
   $Body .= "How did they hear about us?: ";
   $Body .= $About;
   $Body .= "\n";
   $Body .= "What would you like us to do for you?: ";
   $Body .= $Ask;
   $Body .= "\n";
   $Body .= "Email: ";
   $Body .= $EmailFrom;
   $Body .= "\n";
   $Body .= "Comments: ";
   $Body .= $Comments;
   $Body .= "\n";


   // send email 

   $success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");


   // redirect to success page 

   if ($success){
    print "<meta http-equiv=\"refresh\" content=\"0;URL=WUok.html\">"; 
   }
   else{
    print "<meta http-equiv=\"refresh\" content=\"0;URL=WUerror.html\">";
   }

  php?>

</body>

</html>

Link to comment
Share on other sites

  $EmailTo =   "ornclo@aol.com,ornclo@aol.com";

 

Why do you have that duplicated?

 

Are you saying that the email is not being sent? You are also double trimming, I do not think that is needed, also you use Trim, not sure if it matters but it should be trim since php is case sensitive it may matter.

 

 

Link to comment
Share on other sites

Okay, did as you said and took out all the TRIM.

Not to be incrediably stupid, but did I need to take out the "stripsplashes" as well?

 

This is the error I get now:

Parse error: parse error, unexpected T_IS_EQUAL in /home/content/a/c/h/achurch4life/html/emailme.php on line 46

 

 

Link to comment
Share on other sites

I did not mean take out all Trim, just replace the Trim with trim and then take out trim from your if statements. You are already trimming when you assign the variables, no need to trim again.

 

The error you have, chances are it is from removing the trim and forgetting to remove a ).

 

Update that and re-post the updated code so I can see what we are working with.

Link to comment
Share on other sites

okay, now I'm back to just having the error.html page show up.

 


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>
   
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  
  <title>Emailing Form Data</title>
  
</head>

<body>

<?php 
   
  ini_set ("display_errors", "1");
  error_reporting(E_ALL);

  //declaration of variables

  $EmailFrom = trim(stripslashes($_POST['EmailFrom'])); 
  $EmailTo =   "ornclo@aol.com";
  $Subject =   "Women United Contact";
  
  $Name =     trim(stripslashes($_POST['name']));
  $Address =  trim(stripslashes($_POST['address']));
  $City =     trim(stripslashes($_POST['city']));
  $State =    trim(stripslashes($_POST['state']));
  $Phone1 =   trim(stripslashes($_POST['phone1']));
  $Phone2 =   trim(stripslashes($_POST['phone2']));
  $Phone3 =   trim(stripslashes($_POST['phone3']));
  
  $Church =   trim(stripslashes($_POST['visit']));
  $About =    trim(stripslashes($_POST['hear']));
  $Ask =      trim(stripslashes($_POST['help']));

  $Comments = trim(stripslashes($_POST['comments'])); 


  // validation

  $validationOK=true;

   if (($EmailFrom)=="") $validationOK=false;
   if (($Name)=="")      $validationOK=false;
   if (($Address)=="")   $validationOK=false;
   if (($City)=="")      $validationOK=false;
   if (($State)=="" )    $validationOK=false;
   if (($Phone1)=="")    $validationOK=false;
   if (($Phone2)=="")    $validationOK=false;
   if (($Phone3)=="")    $validationOK=false;
    
   if (($Comments)=="")  $validationOK=false;
   
   if (!$validationOK) {
    print "<meta http-equiv=\"refresh\" content=\"0;URL=WUerror.html\">";
    exit;
   }


   // prepare email body text

   $Body .= "";
   $Body .= "Name: ";
   $Body .= $Name;
   $Body .= "\n";
   $Body .= "Address: ";
   $Body .= $Address;
   $Body .= "\n";
   $Body .= "City: ";
   $Body .= $City;
   $Body .= "\n";
   $Body .= "State: ";
   $Body .= $State;
   $Body .= "\n";
   $Body .= "Phone: ";
   $Body .= $Phone1;
   $Body .= "-";
   $Body .= $Phone2;
   $Body .= "-";
   $Body .= $Phone3;
   $Body .= "\n";
   $Body .= "Attended Church of God?: ";
   $Body .= $Church;
   $Body .= "\n";
   $Body .= "How did they hear about us?: ";
   $Body .= $About;
   $Body .= "\n";
   $Body .= "What would you like us to do for you?: ";
   $Body .= $Ask;
   $Body .= "\n";
   $Body .= "Email: ";
   $Body .= $EmailFrom;
   $Body .= "\n";
   $Body .= "Comments: ";
   $Body .= $Comments;
   $Body .= "\n";


   // send email 

   $success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");


   // redirect to success page 

   if ($success){
    print "<meta http-equiv=\"refresh\" content=\"0;URL=WUok.html\">"; 
   }
   else{
    print "<meta http-equiv=\"refresh\" content=\"0;URL=WUerror.html\">";
   }

  php?>

</body>

</html>

Link to comment
Share on other sites

Notice: Undefined index: city in /home/content/a/c/h/achurch4life/html/emailme.php on line 29

 

When I tried running your form that was the error.

 

 

Sasa's right, you have 2 "address" fields, you need to change the second one to "city".

 

 

I believe maq pointed out this error earlier. You need to modify that WUcontact.html and change the above like maq said and it should work.

Link to comment
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.