Radio Buttons in a PHP Form

Hi everyone.

Can someone please have a look at the following code and tell me what I’m doing wrong?

I have a form on one of my clients websites (a photographer) which allows the client to select the size of prints they require (using 6 radio buttons underneath the corresponding size for each image) and a text box at the end of the row where they can enter the quantity of prints they require.

I am getting the error (in Google Chrome) “The website encountered an error while retrieving http://…/purchase.php. It may be down for maintenance or configured incorrectly”

A shortened version of the PHP code is as follows:

<?php $to = "[email protected]"; $name = $_POST['name']; $address = $_POST['address']; $email = $_POST['email']; $tel = $_POST['tel']; $img1size = $_POST['img1size']; $1qty = $_POST['1qty'];

$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”;
$sent = mail($to, $subject, $body) ;
if($sent)
{echo “”;}
else
{echo “window.location = ‘error.html’;</script”;}
?>

A shortened version of the HTML for this form is:

Name:
 
Address:
   
   
Email:
 
Tel:
 
   
Select the images and sizes you wish to purchase from the list below.


 
8" x 6"
10" x 8"
20" x 16"
Framed
20" x 16"
Canvas
32" +
Framed
32"+
Canvas
Quantity
 

The form works fine when I upload and test the first part of the form (name, address, email and tel) but when I add the code for the radio buttons I get the error message.

Any help would be greatly appreciated.

Not sure how adding radio buttons to html code would cause such error. But I noticed you’re redirecting using javascript, while the rest of your code is PHP. It is more logical to redirect using PHP, like this:
[php]header(“Location: purchty.html”);
exit;[/php]

When you’re redirecting using javascript, it is supposed that your current HTML page is first loaded to a client browser, and then javascript redirects to another page. While using PHP, you’re sending redirection headers from server side, without sending any intermediate page to browser.

Thanks for this.

It certainly does make sense to get rid of the java and use php. I copied my 1st php code from another tutorial site and haven’t really changed anything I didn’t have to.

As for the form not working, the part which did work on it’s own (name, address, email and tel) worked fine, but as soon as I added the first line of the purchase options with radio buttons it stopped working.

I have just gone back through it and have taken out all the numbers in the radio button names (img1qty became imgoneqty) and it now works.

Is this a problem with php where you cannot have numbers as either part of the button name or in the actual php fields?

Thanks again for your assistance.

It is Ok to use digits in PHP variable names, but maybe having digits in html form field names cause problem in Chrome?

Sponsor our Newsletter | Privacy Policy | Terms of Service