i want to generate a student id,
this is my code

it is saving but, no output in dB.

$yr=date('Y');
	$id=mysql_insert_id();--auto_increment
	$b="MATH"."$yr"."$id";
	$a=$_POST['b'];

	MATH201201 -- i want my output to be this,

Recommended Answers

All 3 Replies

There are no leading zeros in auto-incremented ids so you will only ever get MATH 20121 as your code is. If you want to include a zero you will have to put it in

$b="MATH"."$yr".0."$id";
Member Avatar for diafol

As broj1 put it, string padding will probably be the way to go with this. However, your format will limit capacity to 99 users. I can't see what you're trying to do with the post and variable, but anyway, you're better off not using any padding, or if you have to, ensure that the padding is sufficiently big to allow as many users as you need.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.