Why is $if (isset($_GET['edit']) returning empty value when it's inside if (isset($_POST['add_submit']) but it's returning the value that I want When it's not inside if (isset($_POST['add_submit']) and how to fix it. Thank you.

   if (isset($_POST['submit']) ) {

       $brand = $_POST['brand']); 

      if (isset($_GET['edit']) ) {
           $sql = "UPDATE brand SET brand = '$brand' WHERE Bra_ID = '29'";
           $stmt = $con->prepare($sql);
           $stmt->execute();
           header("Location: brands.php");
           exit();
      } 
         $sql = "INSERT INTO brand(brand) VALUES('$brand')";
          $stmt = $con->prepare($sql);
          $stmt->execute();
          header("Location: brands.php");
          exit();
 }

I don't see if (isset($_POST['add_submit'])) anywhere in your code. Please show the code that includes that and then I can let you know if there are any typos that might be causing issues.

However, I do notice that on both lines 6 and 12 you are inserting $brand into the database, when $brand is pulled in from a POST request. It's very important for you to sanitize this before submitting it to your database, or you can be in danger of an SQL injection attack.

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.