Trying to get the value of a radio button in HTML to calculate the final price in PHP, then echo it on the page html

I've been attempting to get the value/name/id from my radio to be called into the PHP part of my page to process the final price of the item, but when I run the page after I get the error: Parse error: syntax error, unexpected variable "$processorValue" in D:\xampp\htdocs\PHP_Assignment\Order.php on line 117 Here is the radio part of the HTML:

<label>Processor</label><br>
  <form method="POST">
      <input type="radio" name="processor" value="processor1" checked>AMD Ryzen 4900H
      <input type="radio" name="processor" value="processor2">AMD Ryzen 4900HS
  </form><br>

  <label>Storage</label><br>
  <form method="POST">
      <input type="radio" name="storage" value="storage1" checked>256GB SDD + 512MB HDD
      <input type="radio" name="storage" value="storage2">256GB SDD + 1TB HDD
  </form><br>

  <label>Warranty</label>
  <form method="POST">
      <input type="radio" name="warranty" value="warranty1" checked>2 Years
      <input type="radio" name="warranty" value="warranty2">3 Years
  </form>

  <label>Delivery</label>
  <form method="POST">
      <input type="radio" name="delivery" value="delivery1" checked>Self Pick-up
      <input type="radio" name="delivery" value="delivery2">Express Courier
  </form><br>

here is the PHP, within the same page (as it is the only one running PHP):

<?php

$laptop1 = 1600

//if

$processorValue = $_POST['processor'];
$storageValue = $_POST['storage'];
$warrantyValue = $_POST['warranty'];
$deliveryValue = $_POST['delivery'];

if ($processorValue = "processor2") {
    $laptop2 = $laptop1 + 109;
    $laptop1 = $laptop2;
}
if ($storageValue = "storage2") {
    $laptop2 = $laptop1 + 99;
    $laptop1 = $laptop2;
}
if ($warrantyValue = "warranty2") {
    $laptop2 = $laptop1 + 27;
    $laptop1 = $laptop2;
}
if ($deliveryValue = "delivery2") {
    $laptop2 = $laptop1 + 30;
    $laptop1 = $laptop2;
}



?>

What am I doing wrong here? It's my first 2 months with PHP/HTML and I'd greatly appreciate some help. Thank you.

EDIT: $laptop1 value now has a ; at the end, thank you. It was careless of me. if ($processorValue == "processor2") and the following have been rectified, but now the error is printed as: Undefined array key "processor" in D:\xampp\htdocs\PHP_Assignment\Order.php, and so on for the next 3 $storageValue, $warrantyValue, and $deliveryValue respectively



Read more here: https://stackoverflow.com/questions/66998960/trying-to-get-the-value-of-a-radio-button-in-html-to-calculate-the-final-price-i

Content Attribution

This content was originally published by Martin at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: