SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Wizard
    Join Date
    May 2012
    Posts
    1,087
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Post updating table problem

    Hi, I am having problem in my update,how can i add like this number in php

    lets assume that the value of my post is "00000010"

    how can i add so that it will be like "00000011" and then the next update will be "00000012" and etc....

    my code doesn't work it will give only "1"

    Code:
       
       $num = $_POST['bookno'];
    
       $num = $num + 1;
        
        $sql = "update mytable set `bkno` = '$num' where `bkcode` = '25'";
    
        $result = mysql_query($sql);
    
        if(!$result){
          die("failed to update".mysql_error());
      }

    Can you help me please.Thank you in advance.

  2. #2
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,492
    Mentioned
    161 Post(s)
    Tagged
    4 Thread(s)
    Do an echo of $_POST['bookno'] and $sql

  3. #3
    SitePoint Wizard
    Join Date
    May 2012
    Posts
    1,087
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by guido2004 View Post
    Do an echo of $_POST['bookno'] and $sql
    Hi thank you for the reply,here is the result of my echo.

    post=00000002 sql=1

    the value of my num is 00000002 and the echo is correct.

    so how can i add 1 so that it will be 00000003 and it will update to the column and it will store 00000003

    i tried this but it will not work.

    $num = $num + 1;
    but the result is 1 i am expecting the result to be 00000003
    Thank you in advance.

  4. #4
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,748
    Mentioned
    69 Post(s)
    Tagged
    0 Thread(s)
    How did you manage to echo $sql and get out "1"? Are you sure you didnt echo $num instead?
    Never grow up. The instant you do, you lose all ability to imagine great things, for fear of reality crashing in.

  5. #5
    SitePoint Wizard
    Join Date
    May 2012
    Posts
    1,087
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by StarLion View Post
    How did you manage to echo $sql and get out "1"? Are you sure you didnt echo $num instead?
    hi StarLion, thank you for the reply,

    this is how i echo
    echo "post=".$_POST['bookno'];
    my mistake for the echo of my sql.

    here is i echo again, this is the result
    $num= $num + 1;
    $sql = "update mytable set `bkno` = '$num' where `bkcode` = '25'";

    echo "sql=".$sql;

    sql=update mytable set `bkno` = '1' where `bkcode` = '25'

  6. #6
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,748
    Mentioned
    69 Post(s)
    Tagged
    0 Thread(s)
    So PHP is definately the one choking that down...
    Interesting.
    You could try $num = str_pad(((int)$num + 1),8,"0",STR_PAD_LEFT);
    Never grow up. The instant you do, you lose all ability to imagine great things, for fear of reality crashing in.

  7. #7
    SitePoint Wizard
    Join Date
    May 2012
    Posts
    1,087
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by StarLion View Post
    So PHP is definately the one choking that down...
    Interesting.
    You could try $num = str_pad(((int)$num + 1),8,"0",STR_PAD_LEFT);
    Hi starlion, i tried but it's not working...

    it will always update 00000001

  8. #8
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,492
    Mentioned
    161 Post(s)
    Tagged
    4 Thread(s)
    Could you try this:
    PHP Code:
    $num $_POST['bookno'];
    var_dump($_POST['bookno']);
    var_dump($num);
    $num $num 1;
    var_dump($num); 

  9. #9
    SitePoint Wizard
    Join Date
    May 2012
    Posts
    1,087
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by StarLion View Post
    So PHP is definately the one choking that down...
    Interesting.
    You could try $num = str_pad(((int)$num + 1),8,"0",STR_PAD_LEFT);
    Hi StarLion, sorry for the last reply my mistake i got wrong spell for my variables...and it is now working thank you so much for helping me.


Bookmarks

Posting Permissions

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