1
View dsmflash's reputation
Posted January 21 '09 at 05:46 PM
Posts: 40
Hi,
I have a client who needs a form to produce a unique 6 digit sequential number, like a reference or invoice number, upon submission and the form results emailed to the user with the number as well.
1. can anyone give me some direction on this
2. will it require a database
Thanks
Advertisement
Register for free to hide these ads and participate in discussions!
2
1,251 points at
99%
Posted January 21 '09 at 10:14 PM
Posts: 3,096
I would recommend you use a database (MySQL) because it can create
a unique number for each added entry AND save the data for other uses,
such as saving name, email address, etc.
Now, depending on how sensitive, or secure the site needs to be, you could
do this without a MySQL database, but it would not be as secure. Your "database"
in that case would be a simple text file stored on your website.
You also could create a 6 digit random number instead of sequential...
Pretend my number is 100123, and you are using sequential numbers ...
I know that someone has number 100122 and 100121.
Depending on what your website is all about, perhaps knowing someone
else's number is not a good thing?
With MySQL, each person would have a unique ID number that is used for
the admin, but another field with a random 6-digit ID could be used along with
the MySQL ID record.
So, think about these things and let us know if you've changed what you want.
If it's zero degrees outside today, and it's supposed to be twice as cold tomorrow, how cold is it going to be?
3
View dsmflash's reputation
Posted January 21 '09 at 11:12 PM
Posts: 40
Thanks for the help.
I believe the project calls for use on an intranet.
I don't believe security is a major issue, just the unique number for each form submission. Its just a reference number that will be unique to that user. I just want that number and the form results to be sent to them and the user.
I have been Googling and figured that i would have to create a unique id field in my database.
I'm not much of a database or php person, but i think i might be able to figure it out. I would just create code that outputs the MySql unique id field into the form results, right?
thanks again!
4
1,251 points at
99%
Posted January 22 '09 at 09:34 AM
Posts: 3,096
You wouldn't need to use MySQL if there were no issues with security.
Create a text file called "id.db" and put the starting number on a line,
like this ...
100001
Save that file, upload it and set file permissions to 777, so the script can write to it.
<?php
// Get the email address from the form (from the person using the form).
$email = $_POST['email'];
// Who else will get this email ... the reply email address.
$recipient = "johnsmith@aol.com";
// This is the path and name of your file that holds the sequence number.
$url = "id.db";
// Open the file to see the current sequence number.
$id = file($url);
// Increment the number to the next sequence.
$next = $id[0]+1;
// Go ahead and email the ID number to both parties.
// First create the subject and message ...
$toaddr = $email.",".$recipient;
$subject = "Here is Your ID";
$message = "
Online Form ...
---------------------------------------------------
Here is your ID number: $next
---------------------------------------------------
$email,
Thanks for using our online form to
get your ID number.
---------------------------------------------------
";
// Add any extra headers if you want.
$extraheaders = "From: $recipient\nReply-To: $recipient\n\n";
// Send the actual email to both parties.
if (! mail($toaddr, $subject, $message, $extraheaders))
echo "Mail did not send for some reason.";
// Now, save the new number into the file.
$fh = fopen($url, 'w') or die("can't open file");
fwrite($fh, $next);
fclose($fh);
// Go to this page after the email is sent.
header("Location: index.php");
?>
If it's zero degrees outside today, and it's supposed to be twice as cold tomorrow, how cold is it going to be?
5
View dsmflash's reputation
Posted January 23 '09 at 12:47 PM
Posts: 40
// This is the path and name of your file that holds the sequence number.
$url = "id.db";
can you give me some indication of what this db file would look like, or am i pulling from a unique id field in my database?
thank you.
6
1,251 points at
99%
Posted January 23 '09 at 03:08 PM
Posts: 3,096
The text file called "id.db" is just one number on a line all by itself (the first line).
123123
You could call it "number.txt", "id.txt" ... I just called it "id.db"
I don't like to use the .txt extension on any website files (just a personal preference).
You don't have a database, it's just a text file.
If it's zero degrees outside today, and it's supposed to be twice as cold tomorrow, how cold is it going to be?
7
View dsmflash's reputation
Posted January 23 '09 at 05:58 PM
Posts: 40
thank you so much. i will try it and hopefully i'm smart enough to make it work.
so just put your code in a file, say form.php, and make that the action?
thank you , you are very helpful!!
8
1,251 points at
99%
Posted January 23 '09 at 06:13 PM
Posts: 3,096
Yes ...
<form action="form.php" method="post">
Enter your email: <input type="text" name="email" value=""><br />
<input type="submit" name="submit" value="Get Your ID Now">
</form>
Also ...
Make sure when you upload your file that has the 6 digit number ( id.db ),
that you set the file permission to 777 (or 0777) using your FTP program.
The script needs to write the next number into that file and you'll get an
error ( file permission denied ) if the permission is not set.
EDIT:
If you're really lost, PM me with your FTP account login and I'll go in there
and make it work for you. I just think it's a good idea for you to try ...
you'll learn a lot more by doing this yourself.
.
If it's zero degrees outside today, and it's supposed to be twice as cold tomorrow, how cold is it going to be?
9
View dsmflash's reputation
Posted January 24 '09 at 01:49 AM
Posts: 40
I think the project calls for this to be used on an intranet, i don't know if that makes any difference. i should be able to get it to work. i agree with doing it your self. that's how i've learned everything i know so far.
i just dont program or do db work, but i am learning.
if its ok, i'll pm you if i run into trouble and can't get it resolved.
thanks again.
10
1,251 points at
99%
Posted January 24 '09 at 02:42 PM
Posts: 3,096
intranet should be fine ...
I assume you can run PHP (and it's not an ASP type of site)?
If it's a Windows server with ASP, then PHP is probably not installed.
If it's zero degrees outside today, and it's supposed to be twice as cold tomorrow, how cold is it going to be?
11
View dsmflash's reputation
Posted January 24 '09 at 09:09 PM
Posts: 40
yeah, i hope its not ASP. i shot an email to my contact to make sure. i'm not a fan of windows servers or asp.
i'll post again and let you know.
12
View Preecer's reputation
Posted January 26 '10 at 12:07 PM
Posts: 1
Thanks for this, just what I was looking for. It works on PHP 6 and is very simple to set up.