Jump to content

Recommended Posts

 public function UpdateDetails($fn,$ln,$un,$em) {
    $this->validateFirstname($fn);
    $this->validateLastname($ln);
    $this->validatenewEmail($em,$un);

    if(empty($this->error_array)){
        
$query = $this->con->prepare("UPDATE users SET firstName=:fn, lastName=:ln, email=:em
WHERE username=:un");
                        $query->bindValue(":fn",$fn);
                        $query->bindValue(":ln",$ln);
                        $query->bindValue(":em",$em);
                        $query->bindValue(":un",$un);
                        return $query->execute();
    }

    return false;

    }

here is my profile page

    <?php
    require_once("assest/header.php");
    require_once("class/Account.php");
    require_once("class/fillterform.php");
    require_once("class/Constants.php");

    if(isset($_POST["SaveButtonDetails"])) {
        $account = new Account($con);
        $firstName = filterform::sanitizerFormstring($_POST["firstName"]);
        $lastName = filterform::sanitizerFormstring($_POST["lastName"]);
        $email = filterform::sanitizerFormEmail($_POST["email"]);

        if($account->UpdateDetails($firstName,$lastName,$email,$userLoggedin)){
            //Sucess

            echo "update";
        }
        else {
            ///failure
            echo "No update";
        }
    }
    ?>

    <div class="SettingContainers column">

        <div class="formSection">

        <form method="POST">

        <h2> User Details</h2>

        <?php
            $user= new User($con,$userLoggedin);
            $firstName = isset($_POST["firstName"]) ? $_POST["firstName"] : $user->getfirstName();
            $lastName = isset($_POST["lastName"]) ? $_POST["lastName"] : $user->getlastName();
            $email = isset($_POST["email"]) ? $_POST["email"] : $user->getUsername();
        ?>

        <input type="text" name="firstName" placeholder="Enter First name" value="<?php echo $firstName; ?>">
        <input type="text" name="lastName" placeholder="Enter Last Name" value="<?php echo $lastName; ?>">
        <input type="email" name="email" placeholder="Pleas Enter Email" value="<?php  echo $email; ?>">
        <input type="submit" name="SaveButtonDetails" value="Save" >
        </form>

        </div>

        <div class="formSection">

    <form method="POST">

    <h2> Update Password</h2>

    <input type="password" name="oldpassword" placeholder="Enter Old PassWord">
    <input type="password" name="newpassword" placeholder="Enter New Password">
    <input type="password" name="confirmpassword" placeholder="Confirm New Password">
    <input type="submit" name="SavepasswordDetails" value="Submit" >
    </form>




    </div>

    </div>

The problem is when i can update the data in profile.php page the can't update the data in phpmyadmin and now its (echo No update)

Link to comment
https://forums.phpfreaks.com/topic/314439-no-update-the-data-in-mysql/
Share on other sites

Maybe one of your validations failed, and it set a value in $this->error_array.  You check if that's empty, but if it isn't, you just return false, so the value of that array is set to something you don't make that visible.  You should probably have a method to return it.

 

class Account {
// current code

  public function getValidationErrors() {
     return $this->error_array;
  }
}

And then your code could be something like:

if($account->UpdateDetails($firstName,$lastName,$email,$userLoggedin)){
    //Sucess
    echo "update";
} else {
    ///failure
    echo "No update";
    echo '<pre>' . explode(PHP_EOL, $account->getValidationErrors()) . '</pre>';
}

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.