Results 1 to 4 of 4
  1. #1

    Mysql UPDATE problem

    Hi, Im trying to update a row in a MySQL table.
    It works fine if i set $id as a row that exists, but say for e.g. id set $id as 15, but there is no row 15 it doesnt return an error or anything which i would like it to do.
    PHP Code:
    $id $_GET['id'];
    $query "UPDATE news_posts SET comments=comments+1 WHERE id = '$id'";
    $result mysql_query($query) or die("Query: " mysql_error()); if (!$result) { exit(); } 
    Does anyone know how to resolve this?

    Thanks in Advance,
    Matt
    http://www.theextremenetwork.com
    MSN: [email protected]

  2. #2
    Join Date
    Oct 2003
    Posts
    115
    Code:
    if (mysql_affected_rows() == 0) {
    echo "error";
    }
    is that what your looking for?

  3. #3
    Thats perfect, thanks.


    Matt
    http://www.theextremenetwork.com
    MSN: [email protected]

  4. #4
    Join Date
    Jul 2003
    Location
    Kuwait
    Posts
    5,099
    You can also use mysql_info() if your PHP version is >= 4.3.0

    It will return information normally viewable by the mysql client.

    For updates, it would return something like :

    Code:
    Rows matched: 65 Changed: 65 Warnings: 0
    Which you can parse to get relevant information.
    In order to understand recursion, one must first understand recursion.
    If you feel like it, you can read my blog
    Signal > Noise

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •