Auto calculate form

Hello everybody, im new in php programming and have came to a dead end. I have a homework that i must make till Monday but I dont know how to make it and really need some help.

Im making a simple like order form that will take numbers imputed and save it to a simple txt file that acts like database. Now i need to auto calculate price.

Here is the code for the form, if anybody can help ill really appreciate it. Tyvm and cheers.

[php]










Item Amount Total sum:
Gloves (25 dollars pair)
			<?PHP 
			$price_gloves=125;
			$tot_gloves=$price_gloves*gloves;
			echo "<p>$tot_gloves dollars</p>";
			?>
			
		</td>
	</tr>
	<tr>
		<td>Kimono (<font color="red">100</font> dollars each)</td>
		<td><input name="kimono" type="text" id="kimono" size="4"></td>
		<td>
		
			<?PHP 
			$price_kimono=125;
			$tot_kimono=$price_kimono*kimono;
			echo "<p>$tot_kimono dollars</p>";
			?>
			
		</td>
	</tr>
	<tr>
		<td>Protectors (<font color="red">15</font> dollars set)</td>
		<td><input name="protectors" type="text" id="protectors" size="4"></td>
		<td>
		
			<?PHP 
			$price_protectors=125;
			$tot_protectors=$price_protectors*protectors;
			echo "<p>$tot_protectors dollars</p>";
			?>
			
		</td>
	</tr>
	<tr>
		<td>&nbsp;</td>
		<td><input type="submit" name="Submit" value="Submit"></td>
	</tr>
</table>
[/php]

First of all

This:
[php]<?PHP
$price_gloves=125;
$tot_gloves=$price_gloves*gloves;
echo “

$tot_gloves dollars

”;
?>[/php]

Should be:
[php]<?PHP
$price_gloves=125;
$tot_gloves=$price_gloves*gloves;
echo “

”.$tot_gloves." dollars

";
?>[/php]

*Notice $tot_gloves, similarly it will be the same with others…

And I can’t Pathpredict what you coded in order.php, but to write in a file, this is the code:
[php]$file = fopen(“File Path”,“a”) or exit(“Unable to open file!”);
//the a indicates that if the file doesn’t exist, it will creat it(it won’t create the directory, just the file

fwrite($file, “Write Something”); //to write to next line use \r\n in quotes
fclose($file);[/php]

Sponsor our Newsletter | Privacy Policy | Terms of Service