0

I'm trying to update my database entries with this form:

<form method="post" action="inc/update.php">
    <?php foreach ($links as $row) {
        ?>
        <div class="btn_admin">
            <p>
                <label>Titulo</label>
                <input type="text" name="title[]" value="<?php echo $row["desc"] ?>">
            </p>
            <p>
                <label>Url</label>
                <input type="text" name="url[]" value="<?php echo $row["url"] ?>">
                <input type="hidden" name="id[]" value="<?php echo $row["id"] ?>" />
            </p>

        </div>
    <?php }
    ?>
    <input type="submit" name="submit" value="Update Links" />
</form>

On my update.php file:

if ($_SERVER["REQUEST_METHOD"] == "POST"
        && $_POST["submit"] == "Update Links") {

    include_once 'db.php';
    $db = new PDO(DB_INFO, DB_USER, DB_PASS);

    foreach($_POST['id'] as $id ) {

    $title=$_POST["title"][$id-1];
    $url=$_POST["url"][$id-1];

    $sql = "UPATE index_links
                SET desc=?, url=?
                WHERE id=?";
    $stmt = $db->prepare($sql);
    $stmt->execute(array($title, $url, $id-1));
    $stmt->closeCursor();
    }
}

I've looped through $title and $url and everything is being 'grabbed' correctly, but the query is failing somehow with no errors.

I have even tried messing with erroneous query syntax (like in the query in the example above - "UPATE"), no errors whatsoever... and yes, the foreach loop is being accessed.

This seems like such intro level stuff, but I'm looking at this for an hour or so no and mind=blown... there are other queries (not UPDATE ones) on my project which are working fine.

Your Common Sense
  • 156,878
  • 40
  • 214
  • 345
Jorg Ancrath
  • 1,447
  • 10
  • 34
  • 61
  • 2
    can we assume that `UPATE` is a typo and that you're using `UPDATE` in the real query? – dnagirl Dec 20 '12 at 18:21
  • 2
    Have you taken the SQL you generate and tried running it against database directly? Also, probably an error generated someplace, your just not seeing it. – ficuscr Dec 20 '12 at 18:21
  • @ficuscr: since it's a prepared query, you can't actually see what the thing looks like once the values are subbed in. – dnagirl Dec 20 '12 at 18:23
  • dnagirl, oops, that was part of my attempts to get an error... not even UPDATE is fixing this one... – Jorg Ancrath Dec 20 '12 at 18:23
  • have you looked at the results from PDO::errorInfo? http://ca1.php.net/manual/en/pdo.errorinfo.php – dnagirl Dec 20 '12 at 18:27

1 Answers1

6

In your case, the query probably fails because desc is a reserved word in mySQL.

PDO can be very secretive about its error messages by default. See this question on how to change that.

Community
  • 1
  • 1
Pekka
  • 442,112
  • 142
  • 972
  • 1,088