Hello Everybody,
I am having a serious problem in my hand and i am not able to resolve it..
I have a table in which the primary key is visitor id. I am tryin to generate the visitior id but it is giving me problems.
The code is as follows:
mysql_connect("localhost",$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query="select count(visitor_id) from IWPSD_PERSONAL";
$ctr=mysql_query($query);
if ($ctr==0)
$NextID=1;
else
$NextID=$ctr+1;
The $NextID in all the cases gets a value 4. Now i don't know from where does this number 4 comes, even when there is no records.
If i change the key generation logic , to suppose max of visitor id
mysql_connect("localhost",$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query="SELECT IFNULL(MAX(visitor_id)+1,1) FROM IWPSD_PERSONAL";
$NextID=mysql_query($query);
If i use this $NextID gives me, the value of 0 everytime.
The insert statement that i am using is as follows..
query= "INSERT DELAYED INTO IWPSD_PERSONAL VALUES ('$NextID','$title','$name','$address','$phone','$fax','$email')";
mysql_query($query);
Can anybody tell me where i am wrong?