Hello,

I am trying to Build a Form where the use clicks on check boxes and radio buttons. I want each to have a cash value to them and calculate the final price once the User clicks submit. I've read around the web and have tried changing the value in my checkboxes to the price I want, but his does not seem to be working.

HTML FORM

<form method="post" action="pricing.php">
<input type="radio" name="pictures" value="50">
<input type="radio" name="pictures" value="25">
<input type="radio" name="pictures" value="0">

<input type="checkbox" name="literatures" value="50">
<input type="submit" name="go" value="calculate">
</form>

Pricing.php

if($go){
$pictures=$_POST['pictures'];
$literatures=$_POST['literatures'];
$total=$pictures+$literatures;

echo $total;
}

The code seems to process but nothing appears. Any tips?

Dani AI

Generated

— most likely causes for a blank result are: the PHP never runs (you opened the file with file:// instead of via a webserver), errors are suppressed, or the form-check in your script uses an undefined variable (for example if($go) will be false if $go is not set). Quick checklist to get a visible result:

  • Run the form through a PHP-enabled server (WAMP/XAMPP/MAMP or php -S localhost:8000), and access it with ...
  • Turn on error reporting while debugging: ini_set('display_errors',1); error_reporting(E_ALL);
  • Dump incoming data to see what was posted: var_dump($_POST);

Use a request-safe test instead of relying on an undefined variable. Example server-side pattern to read and sum values safely:

<?php
ini_set('display_errors', 1);
error_reporting(E_ALL);

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $pictures = isset($_POST['pictures']) ? floatval($_POST['pictures']) : 0;
    $literatures = isset($_POST['literatures']) ? floatval($_POST['literatures']) : 0;
    $total = $pictures + $literatures;
    echo 'Total: $' . number_format($total, 2);
}
?>

Notes and common gotchas: an unchecked checkbox or an unselected radio is not included in $_POST, so always use isset() or a default. For multiple checkboxes use an array name (name="extras[]") and sum with array_sum(array_map('floatval', $_POST['extras'] ?? [])). Always validate and cast posted values before arithmetic (clients can send any string). Following the checklist above will show whether the issue is server configuration, form naming, or logic in the PHP.

Hello,

I am trying to Build a Form where the use clicks on check boxes and radio buttons. I want each to have a cash value to them and calculate the final price once the User clicks submit. I've read around the web and have tried changing the value in my checkboxes to the price I want, but his does not seem to be working.

HTML FORM

<form method="post" action="pricing.php">
<input type="radio" name="pictures" value="50">
<input type="radio" name="pictures" value="25">
<input type="radio" name="pictures" value="0">

<input type="checkbox" name="literatures" value="50">
<input type="submit" name="go" value="calculate">
</form>

Pricing.php

if($go){
$pictures=$_POST['pictures'];
$literatures=$_POST['literatures'];
$total=$pictures+$literatures;

echo $total;
}

The code seems to process but nothing appears. Any tips?

Could it be that i Need to use WAMP to test the code? I though Wamp was only if you need to test mysql/php script.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.