jemz
1
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”
$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.
Do an echo of $_POST[‘bookno’] and $sql
jemz
3
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.
How did you manage to echo $sql and get out “1”? Are you sure you didnt echo $num instead?
jemz
5
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’
So PHP is definately the one choking that down…
Interesting.
You could try $num = str_pad(((int)$num + 1),8,“0”,STR_PAD_LEFT);
jemz
7
Hi starlion, i tried but it’s not working…
it will always update 00000001
Could you try this:
$num = $_POST['bookno'];
var_dump($_POST['bookno']);
var_dump($num);
$num = $num + 1;
var_dump($num);
jemz
9
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.