You are basically hitting the maximum limit for an integer value in PHP. As corroborated by you in comment, the result of echo PHP_INT_MAX;
on your server is: 2147483647
. (so, basically a 32-bit build of PHP).
One option is to rebuild the PHP on your server with a 64-bit version. Check this answer to understand the difference in integer range for different builds: https://stackoverflow.com/a/2842548/2469308
Now, in your current case, the number obtained from MySQL: 2001923456789000
is basically overflowing, since it is much higher than the maximum allowed value for an integer. That is why you are seeing wrong results, because once the limit is crossed, PHP would go backwards and start from the lowest allowed negative integer value, and so on.. (in cycles)
Now, in order to solve this issue in a 32-bit PHP, you will have to explicitly typecast the result obtained from MySQL to a Float
datatype. Floats can be used for integer values up to 2^53 + 1.
Try the following:
if($row=mysql_fetch_array($result)) {
$id = (float)$row[0]; // <-- Typecasting to float
$stud_id1 = $id + 1;
echo "<input type='text' class='form-control' id='id' name='id' readonly value=".$stud_id1.">";
}