0

I get this error from the following code. I have tried various things. Cannot understand why it is saying it is not defined. I have put the variables on different lines to identify which one is the problem and the error always follows the line where the propID = :propertyID is. I have an echo statement showing what is set to $propyID and it comes out correct each time I run the code but then says the variable is not defined.

        $exist = "SELECT `propID` FROM `custAdr`
        WHERE `streetAdr` = :street and `zip` = :zip";

        $stmt = $connect->prepare($exist);

        $stmt->execute(array(
          'street' => $street,
          'zip' => $zip,
        ));

          $data = $stmt->fetchAll();

            $propyID = $data[0]['propID'];

            echo $propyID; //shows correct result

            $sql = "UPDATE `custAdr` SET `altCustID` = :custId WHERE `propID` = :propertyID";

                $stmt = $connect->prepare($sql);

                $stmt->execute(['custID' => $custID, 'propertyID' => $propyID,]);
                //Error shows that $propyID is not set even though I have verified it
primo4e
  • 1
  • 3
  • Should it not be `$stmt->execute(array(':street', ':zip'));` (note the `:` before 'street' and 'zip')? See: https://www.php.net/manual/en/pdostatement.execute.php – CD001 Apr 15 '21 at 14:53
  • 1
    `:custId` vs. `'custID'` – Honk der Hase Apr 15 '21 at 15:05
  • 1
    @CD001 They're not mandatory in the call to `execute`, so it shouldn't matter. See [this](https://stackoverflow.com/questions/17386469/pdo-prepared-statement-what-are-colons-in-parameter-names-used-for). – El_Vanja Apr 15 '21 at 15:11
  • The cause lies in the case, as @LarsStegelitz pointed out. `custId` is not the same as `custID`, array indices are case-sensitive. – El_Vanja Apr 15 '21 at 15:12
  • @El_Vanja ... well blow me down, I did not know that :D – CD001 Apr 15 '21 at 15:14
  • @CD001 I've only learned that recently myself, in the same manner - someone pointed out I was wrong in the comments :) – El_Vanja Apr 15 '21 at 15:15
  • Thank you all. For some reason my eyes were missing the little typo of the lowercase d and also missed that the propID in one of the lines was supposed to be propyID. So I have no errors now – primo4e Apr 15 '21 at 20:15

0 Answers0