This is my function:

public function update($params){ try{ $params = array(); $post_id = $_GET['id']; $stmt = $this->conn->prepare("UPDATE $this->tabname SET title= ?, post= ?, updated= ? WHERE id=$post_id "); $stmt->bindParam(1, $params[0], PDO::PARAM_STR); $stmt->bindParam(2, $params[1], PDO::PARAM_STR); $stmt->bindParam(3, $params[2], PDO::PARAM_STR); $stmt->execute(); return true; } catch(PDOException $e) { echo $e->getMessage(); } } 

And this is my editor.php file

 <?php if(isset($_POST["submit"])){ $title = $_POST["title"]; $post = $_POST["post"]; $date = date("Ymd H:i:s"); $params = array("$title","$post","$date"); $update = new DatabaseEdit('posts'); $update->update($params); header("location: posts.php"); } ?> 

When I click submit , it updates on blank lines. What is the problem?

  • 3
    Lay out the form code. I suspect that your $_POST["submit"] missing. WHERE id=$post_id " PDO serves to never do that from a word - ArchDemon

1 answer 1

My friend, you have an array of parameters reset immediately after try , that's the whole snag. bindParam() test :) and also, there is a difference between bindParam() and bindValue() : bindParam() passes the parameter by reference, while bindValue() does not