I am using a form in which people can order products. One of the variables of a product is this:
$product1 = 'Baguette Cheese';
I use this variable in the form like this:
<td><?php echo $product1 ?></td>
<td>€ <?php echo number_format($prijs[$product1], 2); ?></td>
<td><input type="text" name="<?php echo $product1 ?>" size="3" /></td>
Doing it this way, i can not read the name attrib. with $_POST because there is a space between Baguette and Cheese
This does work:
$product1 = 'Cheese-Burger';
But in the first td there is Cheese-Burger displayed and i do not want the hyphen between it. So i thougth: keep the hyphen away and strip the spaces in the name attrib like this:
<td><input type="text" name="<?php echo str_replace(' ', '', $product1) ?>" size="3" /></td>
Unfortunately, this is not working, he can not read the $_POST.
How can i make this work without using hyphen or underscore between Baguette and Cheese ?
When submitting:
if($_SERVER['REQUEST_METHOD'] == 'POST')
{
echo $_POST[$product1]; // no result
}