0

i've a little problem with the UPDATE statement. I've read some topics on stackoverflow and others websites but i can't figure out why I'm not able to update my row.

Actually i'm trying to build a little version of Reddit (just for practice) and this script has to change data inside a row (classic edit post page). Thats my code:

$topic_id = $_GET['id'];

if(isset($_POST["submit"])){
    try {
        include ('../script/db_connect.php');
        $conn = new PDO("mysql:host=$db_servername;dbname=$db_name", $db_user, $db_pass);

        $stmt = $conn->prepare("UPDATE topic SET title = :title, text = :text, category = :category WHERE id = :topic_id");
        $utitle = $_POST["title"];
        $utext = $_POST["myTextArea"];
        $category = $_POST["xxx"];

        $stmt->bindParam(':title', $utitle);
        $stmt->bindParam(':text', $utext);
        $stmt->bindParam(':category', $category);

        $stmt->execute();

        if($stmt){
            $conn = null;
            header("Location: ../index.php");
        }
    }
    catch(PDOException $e){
        echo "Error: " . $e->getMessage();
    }
}

I don't have any errors so must be something with the update statement but i can't find what's the problem.

EDIT: Marked as duplicate by "Your Common Sense", what? Can you show me why and how this post is a "duplicate"?

I just cant figure out how resolve my problem and you just marked that as duplicate instead of help, ok.

Emmanuele
  • 71
  • 1
  • 9
  • 1
    `:topic_id` is missing from binding. – Andrei Sep 13 '16 at 09:53
  • Just added this to the message, forgot to write on stackoverflow but no, this isnt the problem :\ – Emmanuele Sep 13 '16 at 09:54
  • Have you *read* the duplicate? (It's linked at the top of this question…) – deceze Sep 13 '16 at 10:12
  • I did, also im gonna take a look to "https://phpdelusions.net/pdo" by "Your Common Sense". However ive solved my problem by myself. Ty Andrew, i didn't bind topic_id correctly and now works fine. – Emmanuele Sep 13 '16 at 11:03

0 Answers0