Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using a Counter on a form 2

Status
Not open for further replies.

abbottboi

IS-IT--Management
Nov 14, 2005
94
CA
Hi,

I was wondering if its possible to add a counter to a form using PHP. Currently my office uses an online form as a short-term solution for a call ticket system for technical support.

With its function in mind i've created a basic online form but would now like it to assign a unique ID number to the email that it sends once submitted. The starting number should be "2007-001"

If this is possible using some short of simple PHP please let me know. :)
 
ok so upload to the same directory? whatever.txt file with a "0" zero in it?

change [$filename] to whatever.txt?
 
Yes that is correct. Should not have any problem after that.


----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
kinda the same: :(

Warning: filesize(): Stat failed for counter.cnt (errno=2 - No such file or directory) in /home/advancement/final_adv/callticket.php on line 6

Warning: fread(): Length parameter must be greater than 0. in /home/advancement/final_adv/callticket.php on line 6

Warning: fopen(counter.cnt): failed to open stream: Permission denied in /home/advancement/final_adv/callticket.php on line 10

Warning: fwrite(): supplied argument is not a valid stream resource in /home/advancement/final_adv/callticket.php on line 12

Warning: fclose(): supplied argument is not a valid stream resource in /home/advancement/final_adv/callticket.php on line 13

-----------------------------
<?php
function unique_id()
{
$filename = "counter.cnt";
$handle = fopen("whatever.txt", "r");
$fcontents = fread($handle, filesize($filename));
fclose($handle);
$mycounter=$fcontents+1;
$ID="2007_" . $mycounter;
$handle = fopen($filename, "w");
$fcntr=$mycounter;
fwrite($handle,$fcntr);
fclose($handle);
return $ID;
}
?>

----------------------------------

Sorry, any help is appreciated.
 
You changed the wrong variable:

change this:
Code:
<?php
function unique_id()
{

[red]$filename = "counter.cnt";[/red] to 
[blue]$filename="whatever.txt";[/blue]
Code:
$handle = fopen([red]$filename[/red], "r"); [green]This should stay the same. [/green]

----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
got this, maybe i have a permission problem?
Code:
Warning: fopen(whatever.txt): failed to open stream: Permission denied in /home/advancement/final_adv/callticket.php on line 10

Warning: fwrite(): supplied argument is not a valid stream resource in /home/advancement/final_adv/callticket.php on line 12

Warning: fclose(): supplied argument is not a valid stream resource in /home/advancement/final_adv/callticket.php on line 13
 
It looks like you have a permission issue. It's not letting PHP open the file, I wonder why.

You'll have to check the permissions on your webhost.



----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Yeah its possible.

Thanks so much, i'll let you know what happens by re-posting. Good day to ya.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top