Web Design Forum: PHP Form not working - Web Design Forum

Jump to content

WDF
WDF Premium Memberships Reseller Hosting
Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

PHP Form not working Rate Topic: -----

#1 User is offline   mcfly01 

  • Forum Newcomer
  • Pip
  • Group: Members
  • Posts: 8
  • Joined: 18-February 10
  • Reputation: 0
  • Gender:Male
  • Location:Lancashire
  • Experience:Beginner
  • Area of Expertise:I'm Learning

Posted 15 March 2010 - 09:08 PM

Hi all,

wonder if you can help me.

I'm new to websites etc... I've put together a website for work and i've got a contact us page with a PHP file to email me the form when completed, this is all working but when i get the email its not showing any other the entered text.

I beleive the words have to be the same in the form as to the PHP, i have checked all this, spelling and upper/lower case but still nothing.

Can anyone please help me.

Thanks.
0

#2 User is online   andyl 

  • Web Guru huh...
  • PipPipPipPipPip
  • Group: Members
  • Posts: 1,414
  • Joined: 21-January 10
  • Reputation: 191
  • Gender:Male
  • Location:Surrey / HANTS
  • Experience:Intermediate
  • Area of Expertise:Web Developer

Posted 15 March 2010 - 09:14 PM

You need to post the code for us to help :good:
0

#3 User is offline   mcfly01 

  • Forum Newcomer
  • Pip
  • Group: Members
  • Posts: 8
  • Joined: 18-February 10
  • Reputation: 0
  • Gender:Male
  • Location:Lancashire
  • Experience:Beginner
  • Area of Expertise:I'm Learning

Posted 15 March 2010 - 09:19 PM

PHP scrip below.

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

$EmailFrom = Trim(stripslashes($_POST['email']));
$EmailTo = "info@test.com";
$Subject = "Website Enquiry";
$Name = Trim(stripslashes($_POST['name']));
$Contact_Number = Trim(stripslashes($_POST['number']));
$Email = Trim(stripslashes($_POST['email']));
$Message = Trim(stripslashes($_POST['message']));

// prepare email body text
$Body = "";
$Body .= "Name: ";
$Body .= $name;
$Body .= "\n";
$Body .= "Contact Number: ";
$Body .= $number;
$Body .= "\n";
$Body .= "Email: ";
$Body .= $email;
$Body .= "\n";
$Body .= "Message: ";
$Body .= $message;
$Body .= "\n";

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

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

#4 User is offline   webdesigner93 

  • Web Guru
  • PipPipPipPipPip
  • Group: Members
  • Posts: 1,858
  • Joined: 22-September 09
  • Reputation: 212
  • Gender:Male
  • Experience:Web Guru
  • Area of Expertise:Web Developer

Posted 15 March 2010 - 09:54 PM

View Postmcfly01, on 15 March 2010 - 09:19 PM, said:

PHP scrip below.

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

$EmailFrom = Trim(stripslashes($_POST['email']));
$EmailTo = "info@test.com";
$Subject = "Website Enquiry";
$Name = Trim(stripslashes($_POST['name']));
$Contact_Number = Trim(stripslashes($_POST['number']));
$Email = Trim(stripslashes($_POST['email']));
$Message = Trim(stripslashes($_POST['message']));

// prepare email body text
$Body = "";
$Body .= "Name: ";
$Body .= $name;
$Body .= "\n";
$Body .= "Contact Number: ";
$Body .= $number;
$Body .= "\n";
$Body .= "Email: ";
$Body .= $email;
$Body .= "\n";
$Body .= "Message: ";
$Body .= $message;
$Body .= "\n";

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

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


Ok one reason might be is ur not checking if the form is even filled in first so its just going to send blank values right when you run the script unless you check to make sure the form has been submmitted first. :)
0

#5 User is offline   jnicol 

  • Forum Newcomer
  • Pip
  • Group: Members
  • Posts: 52
  • Joined: 15-March 10
  • Reputation: 0
  • Gender:Male
  • Experience:Advanced
  • Area of Expertise:Web Designer

Posted 16 March 2010 - 03:26 AM

PHP variable names are case sensitive. $Email is NOT the same as $email. Make sure the variable names match exactly.
0

#6 User is offline   mcfly01 

  • Forum Newcomer
  • Pip
  • Group: Members
  • Posts: 8
  • Joined: 18-February 10
  • Reputation: 0
  • Gender:Male
  • Location:Lancashire
  • Experience:Beginner
  • Area of Expertise:I'm Learning

Posted 16 March 2010 - 11:01 AM

Thanks for your replies. I have checked the names for and they are all in the same case format.

Where should i go from here?

Thanks for you help guys.
0

#7 User is online   notbanksy 

  • Refreshingly Belligerent Marxist
  • PipPipPipPipPip
  • View gallery
  • Group: Members
  • Posts: 3,839
  • Joined: 14-February 08
  • Reputation: 168
  • Gender:Male
  • Location:Darkest rural Somersetshire
  • Experience:Advanced
  • Area of Expertise:Copywriter

Posted 16 March 2010 - 11:15 AM

To stop the form from submitting empty values on page load, put an if statement around your script like so:

<?php
if ($_POST){
// form processing code goes here
}
?>


Good luck :)
0

#8 User is offline   jnicol 

  • Forum Newcomer
  • Pip
  • Group: Members
  • Posts: 52
  • Joined: 15-March 10
  • Reputation: 0
  • Gender:Male
  • Experience:Advanced
  • Area of Expertise:Web Designer

Posted 16 March 2010 - 08:35 PM

View Postmcfly01, on 16 March 2010 - 11:01 AM, said:

I have checked the names for and they are all in the same case format.


OK - it's just that in the PHP snippet you posted, the casing was different:

$Email = Trim(stripslashes($_POST['email']));
$Body .= $email;

But assuming you've corrected this... what webdesigner93 and notbanksy said!
0

#9 User is online   andyl 

  • Web Guru huh...
  • PipPipPipPipPip
  • Group: Members
  • Posts: 1,414
  • Joined: 21-January 10
  • Reputation: 191
  • Gender:Male
  • Location:Surrey / HANTS
  • Experience:Intermediate
  • Area of Expertise:Web Developer

Posted 17 March 2010 - 12:58 PM

If you post the HTML for the form which is used for the submission, I'll try to fix it up for you.
0

#10 User is offline   mcfly01 

  • Forum Newcomer
  • Pip
  • Group: Members
  • Posts: 8
  • Joined: 18-February 10
  • Reputation: 0
  • Gender:Male
  • Location:Lancashire
  • Experience:Beginner
  • Area of Expertise:I'm Learning

Posted 20 March 2010 - 06:02 PM

View Postandyl, on 17 March 2010 - 12:58 PM, said:

If you post the HTML for the form which is used for the submission, I'll try to fix it up for you.

Hi Andy,

See below which is different to the PHP above.

HTML
<table width="450" border="0" align="left" id="ContactUs">
<tr>
<td width="120" align="left">Forename</td>
<td width="325" align="left"><form id="form1" name="form1" method="post" action="">
<input type="text" name="forname" id="forname" />
</form></td>
</tr>
<tr>
<td width="120" align="left">Surname</td>
<td align="left"><form id="form2" name="form2" method="post" action="">
<label>
<input type="text" name="surname" id="surname" />
</label>
</form></td>
</tr>
<tr>
<td width="120" align="left">Company Name</td>
<td align="left"><form id="form3" name="form3" method="post" action="">
<label>
<input type="text" name="companyname" id="companyname" />
</label>
</form></td>
</tr>
<tr>
<td width="120" align="left">Email</td>
<td align="left"><form id="form4" name="form4" method="post" action="">
<label>
<input type="text" name="email" id="email" />
</label>
</form></td>
</tr>
<tr>
<td width="120" align="left"><form id="form5" name="form5" method="post" action="send_eNewsletter.php">
<label>
<input type="submit" name="Submit" id="Submit" value="Submit" />
</label>
</form></td>
<td align="left">&nbsp;</td>
</tr>
</table>

PHP
<?php

$EmailFrom = Trim(stripslashes($_POST['email']));
$EmailTo = "mdainty85@o2.co.uk";
$Subject = "eNewsletter Subscription";
$Forename = Trim(stripslashes($_POST['forename']));
$Surname = Trim(stripslashes($_POST['surname']));
$Company_Name = Trim(stripslashes($_POST['companyname']));
$Email = Trim(stripslashes($_POST['email']));

$Body = "";
$Body .= "Forename: ";
$Body .= $forename;
$Body .= "\n";
$Body .= "Surname: ";
$Body .= $surname;
$Body .= "\n";
$Body .= "Company Name: ";
$Body .= $companyname;
$Body .= "\n";
$Body .= "Email: ";
$Body .= $email;
$Body .= "\n";

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

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

#11 User is offline   jnicol 

  • Forum Newcomer
  • Pip
  • Group: Members
  • Posts: 52
  • Joined: 15-March 10
  • Reputation: 0
  • Gender:Male
  • Experience:Advanced
  • Area of Expertise:Web Designer

Posted 21 March 2010 - 11:51 PM

Your problem is the HTML - you have wrapped each form input in its own form!

Obviously you should only have one set of <form></form> tags, which should enclose the entire form.
0

#12 User is online   andyl 

  • Web Guru huh...
  • PipPipPipPipPip
  • Group: Members
  • Posts: 1,414
  • Joined: 21-January 10
  • Reputation: 191
  • Gender:Male
  • Location:Surrey / HANTS
  • Experience:Intermediate
  • Area of Expertise:Web Developer

Posted 22 March 2010 - 12:54 AM

Try this HTML, replace all your current HTML with this:

<form id="newsletterForm" name="newsletterForm" method="post" action="send_eNewsletter.php">
<table width="450" border="0" align="left" id="ContactUs">
<tr>
<td width="120" align="left">Forename</td>
<td width="325" align="left">
<input type="text" name="forename" id="forename" />
</td>
</tr>
<tr>
<td width="120" align="left">Surname</td>
<td align="left">
<input type="text" name="surname" id="surname" />
</td>
</tr>
<tr>
<td width="120" align="left">Company Name</td>
<td align="left">
<input type="text" name="companyname" id="companyname" />
</td>
</tr>
<tr>
<td width="120" align="left">Email</td>
<td align="left">
<input type="text" name="email" id="email" />
</td>
</tr>
<tr>
<td width="120" align="left">
<input type="submit" name="Submit" id="Submit" value="Submit" />
</td>
<td align="left">&nbsp;</td>
</tr>
</table>
</form>


There's now only 1 form tag, invalid tags have been removed and a couple of spelling mistakes cleared up which would stop the PHP script working as expected. Remember to +1 if it helps ;)
0

#13 User is offline   sash_007 

  • Trap Grand Marshal Member
  • PipPipPipPip
  • Group: Members
  • Posts: 638
  • Joined: 18-July 09
  • Reputation: 5
  • Gender:Male
  • Experience:Intermediate
  • Area of Expertise:Web Designer

Posted 22 March 2010 - 01:26 AM

View Postmcfly01, on 20 March 2010 - 06:02 PM, said:

Hi Andy,

See below which is different to the PHP above.

HTML
     <table width="450" border="0" align="left" id="ContactUs">
     <tr>
     <td width="120" align="left">Forename</td>
     <td width="325" align="left"><form id="form1" name="form1" method="post" action="">
        <input type="text" name="forname" id="forname" />
        </form></td>
</tr>
      <tr>
      <td width="120" align="left">Surname</td>
      <td align="left"><form id="form2" name="form2" method="post" action="">
        <label>
        <input type="text" name="surname" id="surname" />
        </label>
        </form></td>
</tr>
      <tr>
      <td width="120" align="left">Company Name</td>
      <td align="left"><form id="form3" name="form3" method="post" action="">
        <label>
        <input type="text" name="companyname" id="companyname" />
        </label>
        </form></td>
      </tr>
      <tr>
      <td width="120" align="left">Email</td>
      <td align="left"><form id="form4" name="form4" method="post" action="">
        <label>
        <input type="text" name="email" id="email" />
        </label>
        </form></td>
</tr>
      <tr>
      <td width="120" align="left"><form id="form5" name="form5" method="post" action="send_eNewsletter.php">
        <label>
        <input type="submit" name="Submit" id="Submit" value="Submit" />
        </label>
        </form></td>
      <td align="left">&nbsp;</td>
      </tr>
      </table>

PHP
<?php

$EmailFrom = Trim(stripslashes($_POST['email']));
$EmailTo = "mdainty85@o2.co.uk";
$Subject = "eNewsletter Subscription";
$Forename = Trim(stripslashes($_POST['forename']));
$Surname = Trim(stripslashes($_POST['surname']));
$Company_Name = Trim(stripslashes($_POST['companyname']));
$Email = Trim(stripslashes($_POST['email']));

$Body = "";
$Body .= "Forename: ";
$Body .= $forename;
$Body .= "\n";
$Body .= "Surname: ";
$Body .= $surname;
$Body .= "\n";
$Body .= "Company Name: ";
$Body .= $companyname;
$Body .= "\n";
$Body .= "Email: ";
$Body .= $email;
$Body .= "\n";

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

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




sorry for interrupting but shouldnt this be
$Body .= $surname;
this
$Body .= $Surname;
 i think the case of most of ur variables arent matching 
  :mellow:
0

#14 User is offline   jnicol 

  • Forum Newcomer
  • Pip
  • Group: Members
  • Posts: 52
  • Joined: 15-March 10
  • Reputation: 0
  • Gender:Male
  • Experience:Advanced
  • Area of Expertise:Web Designer

Posted 22 March 2010 - 01:29 AM

View Postsash_007, on 22 March 2010 - 01:26 AM, said:

sorry for interrupting but shouldnt this 
$Body .= $surname;
be this 
$Body .= $Surname;
 i think the case of most of ur variables arent matching 


Yeah that's what I kept saying too! The message didn't seem to get through though...
0

#15 User is offline   mcfly01 

  • Forum Newcomer
  • Pip
  • Group: Members
  • Posts: 8
  • Joined: 18-February 10
  • Reputation: 0
  • Gender:Male
  • Location:Lancashire
  • Experience:Beginner
  • Area of Expertise:I'm Learning

Posted 23 March 2010 - 12:03 PM

Thank you very much for you help guys, my forms are now working with your help. Sorry if i was a bit slow at correcting some issues but I am new to this and do not fully understand its workings.

Thanks again.

Mart
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users