Forum Moderators: coopster

Message Too Old, No Replies

Fairly New to PHP Forms and Really Stuck!

Request for assistance with a php form

         

joebaxi

11:49 pm on May 3, 2011 (gmt 0)

10+ Year Member



Hi everybody.

I am new(ish) to using html forms and php scripts which email the data entered on the form back to my email address.

I have, however, managed to develop around 5 or six forms so far for my website which all work correctly. (My site is an umbrella for other smaller sites so I do need this amount of forms).

I am having problems with one form though. Unfortunately it is the largest of all and I'm really struggling trying to find where the error lies.

In Google Chrome I get the error message (after the form has been filled in and the 'submit' button hit)

"The website encountered an error while retrieving [domain.com...] It may be down for maintenance or configured incorrectly."

In Internet Explorer I get this error:

"The page cannot be displayed. (http 500 - internal server error)"

Would it be possible for one of you geniuses here to have a look at my coding and see if anything jumps out at you?

Basically the form is for a photographers website who will sell copies of prints he has taken. A sample gallery of 10 images has been uploaded with the client being able to click on a button beside the image they wish to purchase, and the size at which it should be printed. They can also input the quantity of prints they require.

In the information below, I have put *'s in where any sites or names have been mentioned, trying to upkeep the boards posting rules, re the advertisement of sites etc. It's my 1st post and I don't want to get into trouble!

As the post is too large with all the information on it I'll have to post the html and php on separate posts which should follow this one.

I know that this is a lot for anyone to go through so I appreciate any little bit of help you can give me.

Many thanks


Joe

joebaxi

11:53 pm on May 3, 2011 (gmt 0)

10+ Year Member



My Form Code (purchase.html):

This post was still to large so I've only included the data for the first 2 lines of the large part of the form:

<form method="post" action="purchase.php" enctype="multipart/form-data">
<table width="744" border="0" cellspacing="0" cellpadding="0" align="center">
<tr>
<td colspan="4">
<div align="right"><font face="Arial, Helvetica, sans-serif" size="4" color="#FFFFFF">Name:</font></div>
</td>
<td width="547">
<input type="text" size="50" name="name">
</td>
</tr>
<tr>
<td colspan="4">
<div align="right"><font face="Arial, Helvetica, sans-serif" size="4"><u><font face="Arial, Helvetica, sans-serif"><font face="Arial, Helvetica, sans-serif"><font color="#FFFFFF"><font size="4"></font></font></font></font></u></font></div>
</td>
<td width="547">&nbsp;</td>
</tr>
<tr>
<td valign="top" colspan="4">
<div align="right"><font face="Arial, Helvetica, sans-serif" size="4" color="#FFFFFF">Address:</font></div>
</td>
<td width="547">
<textarea rows="10" cols="50" name="address" wrap="physical"> </textarea>
</td>
</tr>
<tr>
<td colspan="4">&nbsp;</td>
<td width="547">&nbsp;</td>
</tr>
<tr>
<td colspan="4">&nbsp;</td>
<td width="547">&nbsp;</td>
</tr>
<tr>
<td colspan="4">
<div align="right"><font face="Arial, Helvetica, sans-serif" size="4" color="#FFFFFF">Email:</font></div>
</td>
<td width="547">
<input type="text" size="40" name="email">
</td>
</tr>
<tr>
<td colspan="4">
<div align="right"><font face="Arial, Helvetica, sans-serif" size="4"><u><font face="Arial, Helvetica, sans-serif"><font face="Arial, Helvetica, sans-serif"><font color="#FFFFFF"><font size="4"></font></font></font></font></u></font></div>
</td>
<td width="547">&nbsp;</td>
</tr>
<tr>
<td colspan="4">
<div align="right"><font face="Arial, Helvetica, sans-serif" size="4" color="#FFFFFF">Tel:
</font></div>
</td>
<td width="547">
<input type="text" size="40" name="Tel">
</td>
</tr>
<tr>
<td colspan="4">
<div align="right"><font face="Arial, Helvetica, sans-serif" size="4"><u><font face="Arial, Helvetica, sans-serif"><font face="Arial, Helvetica, sans-serif"><font color="#FFFFFF"><font size="4"></font></font></font></font></u></font></div>
</td>
<td width="547">&nbsp;</td>
</tr>
<tr>
<td colspan="4">&nbsp;</td>
<td width="547">&nbsp;</td>
</tr>
<tr>
<td colspan="5">
<div align="center"><font face="Arial, Helvetica, sans-serif" size="4" color="#FFFFFF">Select
the images and sizes you wish to purchase from the list below.</font></div>
</td>
</tr>
</table>
<br>
<br>
<table width="641" border="0" cellspacing="0" cellpadding="0" align="center">
<tr>
<td width="140">&nbsp;</td>
<td width="10">
<div align="center"><font face="Arial, Helvetica, sans-serif" size="3"><img src="images/spacer.gif" width="10" height="Sizew1"></font></div>
</td>
<td width="51">
<div align="center"><font face="Arial, Helvetica, sans-serif" size="3">8&quot;
x 6&quot;</font></div>
</td>
<td width="10">
<div align="center"><font face="Arial, Helvetica, sans-serif" size="3"><img src="images/spacer.gif" width="10" height="Sizew1"></font></div>
</td>
<td width="56">
<div align="center"><font face="Arial, Helvetica, sans-serif" size="3">10&quot;
x 8&quot;</font></div>
</td>
<td width="10">
<div align="center"><font face="Arial, Helvetica, sans-serif" size="3"><img src="images/spacer.gif" width="10" height="Sizew1"></font></div>
</td>
<td width="66">
<div align="center"><font face="Arial, Helvetica, sans-serif" size="3">20&quot;
x 16&quot;<br>
Framed </font></div>
</td>
<td width="11"><font face="Arial, Helvetica, sans-serif" size="3"><img src="images/spacer.gif" width="10" height="Sizew1"></font></td>
<td width="65">
<div align="center"><font face="Arial, Helvetica, sans-serif" size="3">20&quot;
x 16&quot;<br>
Canvas </font></div>
</td>
<td width="11"><font face="Arial, Helvetica, sans-serif" size="3"><img src="images/spacer.gif" width="10" height="Sizew1"></font></td>
<td width="59">
<div align="center"><font face="Arial, Helvetica, sans-serif" size="3">32&quot;
+<br>
Framed </font></div>
</td>
<td width="11">
<div align="center"><font face="Arial, Helvetica, sans-serif" size="3"><img src="images/spacer.gif" width="10" height="Sizew1"></font></div>
</td>
<td width="57">
<div align="center"><font face="Arial, Helvetica, sans-serif" size="3">32&quot;+<br>
Canvas </font></div>
</td>
<td width="10">
<div align="center"><font face="Arial, Helvetica, sans-serif" size="3"><img src="images/spacer.gif" width="10" height="Sizew1"></font></div>
</td>
<td width="74">
<div align="center"><font face="Arial, Helvetica, sans-serif" size="3">Quantity</font></div>
</td>
</tr>
<tr>
<td width="140"><img src="images/1s.GIF" width="140" height="101"></td>
<td width="10">&nbsp;</td>
<td width="51">
<div align="center">
<input type="radio" name="img1size" value="img1-8x6">
</div>
</td>
<td width="10">
<div align="center"></div>
</td>
<td width="56">
<div align="center">
<input type="radio" name="img1size" value="img1-10x8">
</div>
</td>
<td width="10">
<div align="center"></div>
</td>
<td width="66">
<div align="center">
<input type="radio" name="img1size" value="img1-20x16-framed">
</div>
</td>
<td width="11">
<div align="center"></div>
</td>
<td width="65">
<div align="center">
<input type="radio" name="img1size" value="img1-20x16-canvas">
</div>
</td>
<td width="11">
<div align="center"></div>
</td>
<td width="59">
<div align="center">
<input type="radio" name="img1size" value="img1-32+-framed">
</div>
</td>
<td width="11">
<div align="center"></div>
</td>
<td width="57">
<div align="center">
<input type="radio" name="img1size" value="img1-32+-canvas">
</div>
</td>
<td width="10">
<div align="center"></div>
</td>
<td width="74">
<div align="center">
<input type="text" size="4" name="1qty" value="0">
</div>
</td>
</tr>
<tr>
<td width="140" height="9"><img src="images/spacer.gif" width="1" height="10"></td>
<td width="10" height="9">&nbsp;</td>
<td width="51" height="9">&nbsp;</td>
<td width="10" height="9">&nbsp;</td>
<td width="56" height="9">&nbsp;</td>
<td width="10" height="9">&nbsp;</td>
<td width="66" height="9">&nbsp;</td>
<td width="11" height="9">&nbsp;</td>
<td width="65" height="9">
<div align="center"></div>
</td>
<td width="11" height="9">&nbsp;</td>
<td width="59" height="9">&nbsp;</td>
<td width="11" height="9">&nbsp;</td>
<td width="57" height="9">&nbsp;</td>
<td width="10" height="9">&nbsp;</td>
<td width="74" height="9">&nbsp;</td>
</tr>
<tr>
<td width="140"><img src="images/2s.GIF" width="140" height="101"></td>
<td width="10">&nbsp;</td>
<td width="51">
<div align="center">
<input type="radio" name="img2size" value="img2-8x6">
</div>
</td>
<td width="10">
<div align="center"></div>
</td>
<td width="56">
<div align="center">
<input type="radio" name="img2size" value="img2-10x8">
</div>
</td>
<td width="10">
<div align="center"></div>
</td>
<td width="66">
<div align="center">
<input type="radio" name="img2size" value="img2-20x16-framed">
</div>
</td>
<td width="11">
<div align="center"></div>
</td>
<td width="65">
<div align="center">
<input type="radio" name="img2size" value="img2-20x16-canvas">
</div>
</td>
<td width="11">
<div align="center"></div>
</td>
<td width="59">
<div align="center">
<input type="radio" name="img2size" value="img2-32+-framed">
</div>
</td>
<td width="11">
<div align="center"></div>
</td>
<td width="57">
<div align="center">
<input type="radio" name="img2size" value="img2-32+-canvas">
</div>
</td>
<td width="10">
<div align="center"></div>
</td>
<td width="74">
<div align="center">
<input type="text" size="4" name="2qty" value="0">
</div>
</td>
</tr>

<br>
<table width="325" border="0" cellspacing="0" cellpadding="0" align="center">
<tr>
<td>
<div align="center">
<input type="submit" value="Purchase" name="submit">
</div>
</td>
<td>
<div align="center">
<input type="reset" value="Clear Form" name="reset">
</div>
</td>
</tr>
</table>
</form>

joebaxi

11:54 pm on May 3, 2011 (gmt 0)

10+ Year Member



And finally, my PHP Code (from purchase.php file, stored in the same directory as purchase.html, error.html and purchty.html):

Even though I only included the 1st 2 lines of the form in the html above, I've included the full php file.

<?php
$to = "****@***-***.***";
$name = $_POST['name'];
$address = $_POST['address'];
$email = $_POST['email'];
$tel = $_POST['tel'];
$img1size = $_POST['img1size'];
$1qty = $_POST['1qty'];
$img2size = $_POST['img2size'];
$2qty = $_POST['2qty'];
$img3size = $_POST['img3size'];
$3qty = $_POST['3qty'];
$img4size = $_POST['img4size'];
$4qty = $_POST['4qty'];
$img5size = $_POST['img5size'];
$5qty = $_POST['5qty'];
$img6size = $_POST['img6size'];
$6qty = $_POST['6qty'];
$img7size = $_POST['img7size'];
$7qty = $_POST['7qty'];
$img8size = $_POST['img8size'];
$8qty = $_POST['8qty'];
$img9size = $_POST['img9size'];
$9qty = $_POST['9qty'];
$img10size = $_POST['img10size'];
$10qty = $_POST['10qty'];
$N = count($addon);
$subject = "Purchase from *** ****** ** ***** Website";
$body = "Name: $name \n\n Address: $address \n\n Email: $email \n\n
Tel: $tel \n\n
Image 1 Size: $img1size \n\n Image 1 Quantity: $1qty \n\n Image 2 Size: $img2size \n\n Image 2 Quantity: $2qty \n\n
Image 3 Size: $img3size \n\n Image 3 Quantity: $3qty \n\n Image 4 Size: $img4size \n\n Image 4 Quantity: $4qty \n\n
Image 5 Size: $img5size \n\n Image 5 Quantity: $5qty \n\n Image 6 Size: $img6size \n\n Image 6 Quantity: $6qty \n\n
Image 7 Size: $img7size \n\n Image 7 Quantity: $7qty \n\n Image 8 Size: $img8size \n\n Image 8 Quantity: $8qty \n\n
Image 9 Size: $img9size \n\n Image 9 Quantity: $9qty \n\n Image 10 Size: $img10size \n\n Image 10 Quantity: $10qty \n\n";
$sent = mail($to, $subject, $body) ;
if($sent)
{echo "<script language=javascript>window.location = 'purchty.html';</script>";}
else
{echo "<script language=javascript>window.location = 'error.html';</script";}
?>

enigma1

8:45 am on May 4, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The errors may occur because the server configuration. One thing I noticed you said the purchase html file is purchase.html but in the php code, right after sending the email the file to open states purchty.html

I would expect the server to show 404 if the file is not found but could be something else in the server configuration I cannot see from the posted code.

rocknbil

4:39 pm on May 4, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



There's lots of issues here, unrelated to the problem, but you must try this instead of the Javascript.

if ($sent) { header("Location:purchty.html"); }
else { header("Location:error.html"); }

That also is not likely related to the problem. The way you can debug these is begin taking out bits at a time until you find the issue. For example, set $body = "test"; temporarily, see if it works. Strip your mail function down to a hard coded test, see if it's that. Also I don't see any headers, perhaps your server won't send mail without a from field (which needs to go in the header.)