Database Forum
Web Database Register Members List Calendar FAQ

 
Go Back   Database Forum > Other Database Software > PHP Form Magic
User Name
Password

Reply
 
Thread Tools Search this Thread Display Modes
Question Generating a reference number in PHP
06-01-2008, 11:19 PM #1  

prodempsey
Junior Member

 
Status: Offline
Posts: 5
Join Date: May 2008

I want to generate a reference number based on the time and date the form was completed, and I want to include the reference number in the email to owner, in the autoresponder message to the customer, and to mysql. The problem is, I'm not sure how to implement this reference number string into my PHP file.

Here is the reference number code:

$reference_num_date = date("ymdHis",$reference_num_secs);

for example the code above would return 080601154542

in other words:

01 Jun 2008 15:45:42

Here is my current PHP code without the reference number code:


<?php
# ----------------------------------------------------
# -----
# ----- This script was generated by php form magic 1.1 on 5/29/2008 at 8:03:00 PM
# -----
# ----- http://www.websitedatabases.com
# -----
# ----------------------------------------------------


// Receiving variables
@$fname = addslashes($_POST['fname']);
@$lname = addslashes($_POST['lname']);
@$email = addslashes($_POST['email']);
@$phone = addslashes($_POST['phone']);
@$property = addslashes($_POST['property']);
@$requestor = addslashes($_POST['requestor']);
@$city = addslashes($_POST['city']);
@$servicer = addslashes($_POST['servicer']);
@$state = addslashes($_POST['state']);
@$liens = addslashes($_POST['liens']);
@$zip = addslashes($_POST['zip']);
@$loanstatus = addslashes($_POST['loanstatus']);

// Validation
if (strlen($fname) == 0 )
{
header("Location: error.html");
exit;
}

if (strlen($lname) == 0 )
{
header("Location: error.html");
exit;
}

if (! ereg('[A-Za-z0-9_-]+\@[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+', $email))
{
header("Location: error.html");
exit;
}

if (strlen($email) == 0 )
{
header("Location: error.html");
exit;
}

if (strlen($phone) <10)
{
header("Location: error.html");
exit;
}
if (strlen($phone) >15)
{
header("Location: error.html");
exit;
}

if (strlen($phone) == 0 )
{
header("Location: error.html");
exit;
}

if (strlen($property) == 0 )
{
header("Location: error.html");
exit;
}

if ( strcasecmp($requestor,"Realtor") != 0 && strcasecmp($requestor,"Homeowner") != 0 )
{
header("Location: error.html");
exit;
}

if (strlen($requestor) == 0 )
{
header("Location: error.html");
exit;
}

//Sending Email to form owner
# Email to Owner
$pfw_subject = "New Negotiation Request";
$pfw_email_to = "";
$pfw_message = "fname: $fname\n"
. "lname: $lname\n"
. "email: $email\n"
. "phone: $phone\n"
. "requestor: $requestor\n"
. "property: $property\n"
. "city: $city\n"
. "state: $state\n"
. "zip: $zip\n"
. "servicer: $servicer\n"
. "liens: $liens\n"
. "loanstatus: $loanstatus\n";
@mail($pfw_email_to, $pfw_subject ,$pfw_message ,$pfw_header ) ;

//Sending auto respond Email to user
# Email to Owner
$pfw_header = "From: ";
$pfw_subject = "Negotiation Request Confirmation";
$pfw_email_to = "$email";
$pfw_message = "Hi $fname,\n"
. "Your negotiation request has been received, and you will receive a phone call within the next 24 hours. In most cases a short sale specialist will get back to you within the same day. \n"
. "\n"
. "We will gather some additional information, walk you through the short sale process, and answer any questions you have.\n"
. "\n"
. "In the meantime, please gather the loan numbers for each lien so we can get started as soon as possible.\n"
. "\n"
. "Just to recap, here is the information you submitted:\n"
. "\n"
. "Your name: $fname $string = strtolower($string);
$string = substr_replace($string, strtoupper(substr($string, 0, 1)), 0, 1);$lname\n"
. "Your Phone Number: $phone\n"
. "You are a: $requestor\n"
. "Property Address: $property\n"
. "Property City: $city\n"
. "Property State: $state\n"
. "Property Zip: $zip\n"
. "Mortgage Servicer: $servicer\n"
. "Any Additional Liens: $liens\n"
. "Loan Status: $loanstatus\n"
. "\n"
. "We look forward to talking to you soon. \n"
. "\n"
. "Sincerely,\n"
. "The Simply Short Sales Team\n"
. "www.simplyshortsales.com\n";
@mail($pfw_email_to, $pfw_subject ,$pfw_message ,$pfw_header ) ;

//saving record to MySQL database


@$pfw_strQuery = "INSERT INTO `negrequest`(`fname`,`lname`,`email`,`phone`,`prop erty`,`requestor`,`city`,`servicer`,`state`,`liens `,`zip`,`loanstatus`)VALUES (\"$fname\",\"$lname\",\"$email\",\"$phone\",\"$pr operty\",\"$requestor\",\"$city\",\"$servicer\",\" $state\",\"$liens\",\"$zip\",\"$loanstatus\")" ;
@$pfw_host = "mysql";
@$pfw_user = "prodempsey";
@$pfw_pw = "1234jack";
@$pfw_db = "simplyshortsales";
$pfw_link = mysql_connect($pfw_host, $pfw_user, $pfw_pw);
if (!$pfw_link) {
die('Could not connect: ' . mysql_error());
}
$pfw_db_selected = mysql_select_db($pfw_db, $pfw_link);
if (!$pfw_db_selected) {
die ('Can not use $pfw_db : ' . mysql_error());
}

//insert new record
$pfw_result = mysql_query($pfw_strQuery);
if (!$pfw_result) {
die('Invalid query: ' . mysql_error());
}
mysql_close($pfw_link);

header("Location: thankyou.html");

?>

Last edited by prodempsey; 09-25-2008 at 11:52 PM..
Reply With Quote

Default
06-02-2008, 03:34 PM #2  

twenty1
Senior Member

 
Status: Offline
Posts: 221
Join Date: Mar 2005
Location: Iowa, USA

Add the hidden timestamp to your form.
<FORM ......>
<INPUT TYPE=HIDDEN NAME=TIMESTAMP VALUE="<%=Now()%>">

Add a timestamp field to your db table too. Or if you don't want to store the timestamp just echo in the script your posted to form owner and auto-respond. $pfw_TIMESTAMP = "<%=Now()%>";

cheers
Reply With Quote

Default How do you implement the timestamp?
06-02-2008, 10:10 PM #3  

prodempsey
Junior Member

 
Status: Offline
Posts: 5
Join Date: May 2008

Can you show me how you would implement the timestamp code into my PHP form code above?
Reply With Quote

Default
06-03-2008, 04:47 PM #4  

BigFan
Member

 
Status: Offline
Posts: 62
Join Date: Mar 2005
Location: Austin

Add something along these lines:

(eg)
<?php
$ref_num = date("d/m/y : H:i:s", time());
echo "Your Reference Number is $ref_num";
?>

Add something like this to the //Sending Email to form owner and //Sending auto respond Email to user sections.
Reply With Quote

Default
06-03-2008, 05:11 PM #5  

cu-it-up
Member

 
Status: Offline
Posts: 33
Join Date: Mar 2005

If you want to store in mysql also...

First add a timestamp field to this table. Most host offer a mysql tool like phpmyadmin. Login and add a timestamp field. Name it ref_num for example.

in text editor.

//Sending Email to form owner
# Email to Owner
$ref_num = date("d/m/y : H:i:s", time());
$pfw_subject = "New Request";
$pfw_email_to = "email@home.com";
$pfw_message = "fname: $fname\n"
. "ref_num: $ref_num\n"
. "lname: $lname\n"
. "email: $email\n"
.....
....
... hth Cheers
Reply With Quote

Default
06-06-2008, 07:42 PM #6  

Kayla
Senior Member

 
Status: Offline
Posts: 302
Join Date: Mar 2005
Location: USA

Glad you have solved your coding requirements.
Reply With Quote

Default
10-15-2008, 07:34 AM #7  

JamieAdams
Junior Member

 
Status: Offline
Posts: 6
Join Date: Sep 2008

The reference number that I need to create is the first method as stated above... is there any example u can show me as to how to do?? The number must have only 10 digits.

The first 6 digits (year and month) will stay the same, only the last 4 that is changing throughout the whole month. Then after 1 month, the month will increase by one, after 1 year, the year will increase by 1. The last 4 digits must be reset after every month.

Last edited by Jenn; 10-15-2008 at 02:48 PM.. Reason: moved to proper forum
Reply With Quote

Default
10-22-2008, 03:36 AM #8  

JackSubastian
Junior Member

 
Status: Offline
Posts: 1
Join Date: Aug 2008

What I would like to do is generate a ref number based on time dd/mm/yyyy can
> this be done?

Yes. I personally have always found it easier to work with timestamps,
but...

$reference_num_secs = time();
$reference_num_date = date("ymdHis",$reference_num_secs);

The latter returns, for example:

030116154542

in other words:

16 Jan 2003 15:45:42 -0000

(One subs an upper case "Y" for the lower-case in order to return a four
digit year, IIRC.)
Reply With Quote

Default
10-24-2008, 07:34 AM #9  

GERARDO
Junior Member

 
Status: Offline
Posts: 1
Join Date: Oct 2008

however, my codin gat this point of time is something like this:

<html>
<body>
<%
sql1 = "select ReqMonth from ReqNoRef"
set rs=MSCS.execute(sql1)

if ReqMonth <> (Month(Now)) then
LastReqNo=0000
end if

sql2 = "select LastReqNo from ReqNoRef"
set rs=MSCS.execute(sql2)

if LastReqNo = LastNo then
LastNo = LastNo + 1
end if

sql3="INSERT INTO ReqNoRef (ReqMonth, LastReqNo) values Month(Now), LastNo)"
set rs=MSCS.execute(sql3)

rs.close
set rs=nothing

ReqNo = Right(CStr(Year(Now)) & CStr(Month(Now)& CStr(LastReqNo)), 11)

'Dim MyMth
'MyMth = Month(Now)

'Dim MyYear
'MyYear = Year(Now)

'ReqNo = Right(CStr(Year(Now)) & CStr(Month(Now)& CStr(LastReqNo)), 11)

''ReqNo = Right(CStr(Year(Now)) & CStr(Month(Now)& CStr(Int(Rnd * 1000))), 11)

sql="INSERT INTO Requests (AppnId,DesiredDt,reqTitle,funcReq,FreqVol,Reqtr,R eqtrEmail,ContactNo,Dept,RC,Priority,ApprovOfficer ,ApprovEmail,Savings,Revenue,Benefit,Tester,Tester Contact)"
sql=sql & " VALUES "
sql=sql & "('" & Request.Form("vAppnId") & "',"
sql=sql & "'" & Request.Form("vDesiredDt") & "',"
sql=sql & "'" & Request.Form("vreqTitle") & "',"
sql=sql & "'" & Request.Form("vfuncReq") & "',"
sql=sql & "'" & Request.Form("vFreqVol") & "',"
sql=sql & "'" & Request.Form("vReqtr") & "',"
sql=sql & "'" & Request.Form("vReqtrEmail") & "',"
sql=sql & "'" & Request.Form("vContactNo") & "',"
sql=sql & "'" & Request.Form("vDept") & "',"
sql=sql & "'" & Request.Form("vRC") & "',"
sql=sql & "'" & Request.Form("vPriority") & "',"
sql=sql & "'" & Request.Form("vApprovOfficer") & "',"
sql=sql & "'" & Request.Form("vApprovEmail") & "',"
sql=sql & "'" & Request.Form("vSavings") & "',"
sql=sql & "'" & Request.Form("vRevenue") & "',"
sql=sql & "'" & Request.Form("vBenefit") & "',"
sql=sql & "'" & Request.Form("vTester") & "',"
sql=sql & "'" & Request.Form("vTesterContact") & "')"

'Response.Write(sql)
'Response.End

MSCS.execute(sql)
%>

redirecturl = "change_request.asp"
Response.Redirect redirecturl

</body>
</html>

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

actually, I just need to create a reference number with the year in front, followed by the month and the unique number at the back. It goes something like this "yyyymmuuuu". I've a database to store the month in which the user submit their request and the last reference number created.

Last edited by GERARDO; 10-30-2008 at 01:49 AM..
Reply With Quote

Default
11-05-2008, 05:13 AM #10  

zachary T
Junior Member

 
Status: Offline
Posts: 4
Join Date: Sep 2008

I am currently generating a reference number with the following:

/* Lets calculate a reference number. */

mt_srand ((double)microtime() * 10000000);

$reference_number = mt_rand (1000000,9999999);

What I would like to do is generate a ref number based on time dd/mm/yyyy can this be done?
Reply With Quote

Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump



All times are GMT -5. The time now is 12:04 AM.

Powered by: vBulletin Version 3.7.4
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Database Forums

Help support our forum assistants and product development ->

go to top go to top