-3

I have this code which should update the domainReserved row to 0 from 1, after the payment is made, inserted in database with status approved.

if (isset($_SESSION["cart"])) {
          foreach ($_SESSION["cart"] as $key => $value) {
               foreach ($_SESSION["cart"][$key] as $domain) {
                    $registered = 0;
                    $reserved = 1;
                    $updateDomainSQL = "UPDATE domains SET domainReserved = ? WHERE domainName = ? AND domainReserved = ?";
                    $updateStmt = $dbConn->prepare($updateDomainSQL);
                    $updateStmt->bind_param('isi', $registered, $domain, $reserved);
                }
           }
      }

The problem with this code is that the row is not updated. I want to mention that the domainReserved row is saved as an ENUM with 0 and 1 values.

Before using the code above, I had the code down below which sent me a message that said the code was executed, but there was no update in the database:

 $updateDomainSQL = "UPDATE domains SET domainReserved = 0 WHERE domainName = '$domain'";

 if (isset($_SESSION["cart"])) {
            foreach ($_SESSION["cart"] as $key => $value) {
                foreach ($_SESSION["cart"][$key] as $domain) {
                    $updateDomainSQL = "UPDATE domains SET domainReserved = 0 WHERE domainName = '$domain'";

                    if ($updateStmt = mysqli_prepare($dbConn, $updateDomainSQL)) {
                        if (mysqli_stmt_execute($updateStmt)) {
                            echo "executed: " . $updateDomainSQL . "<br />";
                        } else {
                            echo "ERROR: Could not execute query: $insertDomainSQL. " . mysqli_error($dbConn);
                        }
                        mysqli_stmt_close($updateStmt);
                    }
                }
            }
        }
Dharman
  • 26,923
  • 21
  • 73
  • 125
matei1337
  • 34
  • 8
  • Is `$domain` set somewhere we don't see? – brombeer May 23 '22 at 09:33
  • _"a message that said the code was executed, but there was no update in the database"_ - those are two different things! You are checking whether the statement could successfully be executed there, that means without errors. It does _not_ say anything about whether this UPDATE statement actually changed any data. – CBroe May 23 '22 at 09:35
  • @brombeer I've edited the question, now you can see where I get `$domain` from. – matei1337 May 23 '22 at 09:40

0 Answers0