0

Trying to learn object oriented programming with php but php pdo update query not working properly,
it gives me no error message and the table does not update. Works perfectly when i try to select or insert into the database but update not working.
How can I solve this issue please help, thank you so much.

UPDATE LINK FROM INDEX VIEW


<a href='userupdate?exampleInputName=$row[a_name]&exampleInputPhone=$row[a_mobile]'>UPDATE</a>

CONTROLLER PAGE

<?php
include "MdlUsers.cls.php";
class CtrlUsers extends MdlUsers {
    // update data controller
    public function updateFormUsers($name_data, $number_data) {
        $this->updtFormUsers($name_data, $number_data); // from model
        echo "Successfully updated";
    }
} ?>

MODEL PAGE

<?php
include "Dbh.cls.php";
class MdlUsers extends Dbh {
    // update data model
    protected function updtFormUsers($name_data, $number_data) {
        $sql = "UPDATE reg_tbl SET a_name='$name_data' WHERE a_mobile='$number_data'";
        $stmt = $this->connect()->prepare($sql);
        // print_r($stmt);
        $stmt->execute([$name_data, $number_data]);
    }
} ?>
Your Common Sense
  • 156,878
  • 40
  • 214
  • 345
  • 2
    Welcome. Please read [How to create a Minimal, Reproducible Example](https://stackoverflow.com/help/minimal-reproducible-example) (focus on the "minimal" part.) Remove all code that isn't directly relevant to the issue. Do some proper debugging to narrow down the issue instead of posting a ton of code. – M. Eriksson Mar 14 '20 at 19:48
  • This update `$sql = "UPDATE reg_tbl SET a_name='$name_data' WHERE a_mobile='$number_data'";` doesn't use[`?` or named parameters](https://www.php.net/manual/en/pdo.prepare.php) so wouldn't the `prepare` method (or maybe the `execute`) give an error? – DinoCoderSaurus Mar 14 '20 at 22:00
  • @MagnusEriksson Ok, thanks – user646030 Mar 16 '20 at 05:52
  • _"it gives me no error message"_ you aren't checking for any. See [How can I get useful error messages in PHP?](https://stackoverflow.com/questions/845021/how-can-i-get-useful-error-messages-in-php) – Phil Mar 16 '20 at 05:53
  • There is so much wrong with this code, I don't even know where to start. See [how to include a PHP variable in a mysql statement](https://stackoverflow.com/a/7537500/285587), then [how to connect using PDO], and also **a user is not a database handler** [a user class cannot be an offspring of Dbh class](https://phpdelusions.net/pdo/common_mistakes) – Your Common Sense Mar 16 '20 at 07:52

0 Answers0