i am fetching database value of a column as 0005 , then i am adding 1 to it and save it in the database with a char ABHI but in the database its saved as ABHI6 not ABHI0006. how to do it??
here is the php script
$name = mysqli_real_escape_string($conn, $_POST['name']);
$id = mysqli_real_escape_string($conn, $_POST['id_last']);
$id2=+$id;
$sql="INSERT INTO file (name, unique_id )
VALUES ('$name','$name$id2')";
Use padding for the string
$name = mysqli_real_escape_string($conn, $_POST['name']);
$id = mysqli_real_escape_string($conn, $_POST['id_last']);
$id2 = "$name".str_pad(++$id, 4, "0", STR_PAD_LEFT);
$sql="INSERT INTO file (name, unique_id )
VALUES ('$name','$id2')";
See refrence here
Try with this
$id = "ABHI1";
$IncrementID = substr($id, -1) +1;
echo substr_replace($id,$IncrementID,-1);
Out put
ABHI2
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.