Reference Number...HELP!!!

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
apek
Forum Commoner
Posts: 96
Joined: Tue Jan 06, 2004 11:19 pm
Location: Holiday Plaza Johor Bahru

Reference Number...HELP!!!

Post by apek »

i have a new pronblem...heheh..
I have a submit form that is managed with PHP. On the form, there has to be a reference number that has to be incremented every time a user submits.And the reference number interacts with mysql..

heres my code:

Code: Select all

//---------------------------------------
   //            DATE FUNCTION
   //---------------------------------------
   $Tdate = getdate();
    $datToday = date("d/m/Y");
    $year=$Tdate['year'];
   //---------------------------------------
   //          REFFRENCE NUMBER
   //---------------------------------------

    $query = "Select * from ".$DBprefix." rujAduan";
    $logCursor = mysql_query($query);

    if ($logCursor.$EOF) {
        $refNum = 1;
    } else {
        $refNum = $logCursor["ref"] + 1;
    }

    if ($refNum < 10) {
          $refNumber = "00".$refNum;
     } else {
          if ($refNum < 100) {
              $refNumber = "0".$refNum;
          } else {
              $refNumber = $refNum;
          }
        }

    $referNum = "REF".$refNumber."/".$year;
?>
the output is like REF001/2004..
but when i submit it again,it still show REF001/2004..
it suppose to show REF002/2004 (increment by 1)..
wheres the error??
hmm...help!!!!!!!!!


hmmm..i try to check in my mysql database..
theres a strange thing happens...
the rujAduan table is consist of "ID" and "ref" field...
suppose the "ref" field is increased by 1...(look at the code)
but why must the ID field is increase?
haaaaaa.......HELP!!!!!!!!!!!
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Can you please post the table structure so that we can see what is going on. You'll probably find it easier to use an autoincrementing ID field and then construct the reference from that.

Mac
Post Reply