1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

php update sql not working?

Discussion in 'PHP' started by piniyini, Sep 22, 2005.

  1. #1
    I cant understand why this update script is not working, everything seems ok but it always return the error "could not update post".

    Does anyone know why, here is the script I am using

    
    <?php
    $id = (int) $_GET["id"];
    require_once("./common.php");
    $submitx = $_POST["sx"];
    $connect = @mysql_connect(CONNECT_HOST,CONNECT_USERNAME,CONNECT_PASSWORD) or die ("Could not connect to the host server");
    $database = @mysql_select_db(DB_USERNAME) or die ("Could not connect to the database");
    $select_post = @mysql_query("SELECT text, h1 FROM `".DB_TABLE_POSTS."` WHERE (`id`='$id') LIMIT 0,1") or die ("Could not find post");
    $row_cat = mysql_fetch_array($select_post);
    $post = $row_cat["text"];
    $h1 = $row_cat["h1"];
    @mysql_free_result($select_post);
    if ($submitx)
    {
    $text = $_POST["t"];
    $cmts = (int) $_POST["c"];
    $show = (int) $_POST["s"];
    $feed = (int) $_POST["f"];
    trim($text);
     
    $full_post = $post.' '.$text;
    $add = @mysql_query("UPDATE `".DB_TABLE_POSTS."` SET `text` = '".$full_post."', `comment_status` = '".$cmts."', `show` = '".$show."', `feed` = '".$feed."' WHERE (`id` = '$id') LIMIT 0,1") or die ("Could not update post");
    @mysql_free_result($add);
    @header("location:./s.php"); exit();
    }
    @mysql_close($connect);
    @header("cache-control:no-cache,no-store,must-revalidate");
    @header("pragma:no-cache");
    ?><form action="./mobyadd.php?id=<?php echo($id); ?>" method="post">
    <?php echo($h1); ?> <textarea name="t"></textarea>
    Comments <input type="text" name="c" size="1" maxlength="1" value="1"/>
    Show <input type="text" name="s" size="1" maxlength="1" value="1"/>
    Feed <input type="text" name="f" size="1" maxlength="1" value="1"/>
    <input type="submit" name="sx" value="SUBMIT"/>
    </form>
    
    PHP:
     
    piniyini, Sep 22, 2005 IP
  2. johnt

    johnt Peon

    Messages:
    178
    Likes Received:
    21
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I think its the "LIMIT 0,1". The update statement expects only a row count after LIMIT, not start and end rows like select. Try changing it to "LIMIT 1"
     
    johnt, Sep 22, 2005 IP
  3. piniyini

    piniyini Well-Known Member

    Messages:
    514
    Likes Received:
    26
    Best Answers:
    0
    Trophy Points:
    170
    #3
    nah its not that, i have tried it before and have just tried it again, i dont get it everything looks fine! but it doesnt work, aargh
     
    piniyini, Sep 22, 2005 IP
  4. piniyini

    piniyini Well-Known Member

    Messages:
    514
    Likes Received:
    26
    Best Answers:
    0
    Trophy Points:
    170
    #4
    goy it working! woo hoo
     
    piniyini, Sep 22, 2005 IP
  5. rederick

    rederick Peon

    Messages:
    128
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Toss in a mysql_error(); Maybe that'll help ..

    $add = @mysql_query("UPDATE `".DB_TABLE_POSTS."` SET `text` = '".$full_post."', `comment_status` = '".$cmts."', `show` = '".$show."', `feed` = '".$feed."' WHERE (`id` = '$id') LIMIT 0,1") or die ("Could not update post". mysql_error());
    PHP:
    EDIT:
    ah .... to late ... :)
     
    rederick, Sep 22, 2005 IP
    piniyini likes this.
  6. piniyini

    piniyini Well-Known Member

    Messages:
    514
    Likes Received:
    26
    Best Answers:
    0
    Trophy Points:
    170
    #6
    Rederick you are a star! I was about to pull all my hair out then! Eventhough I said it was working I found out it was only working for some of the posts, you tip found the solution. I was not adding addslashes which caused the query to break on some updates.

    You wont believe how pleased I am right this minute, been trying to get a solution for ages. Right now I feel like smooching you, and hell, I'm not even gay.
     
    piniyini, Sep 22, 2005 IP