//AFTER COLLECTING THE NAME AND PASSWORD FROM THE FORM, we INSERT INTO THE DATABASE named processreg1.php
$addNewDealer = @mysql_query("INSERT INTO dealer_user (dealer_id, d_email, d_pass, signup_date) VALUES (NULL, '".$_POST['d_email']."', '".$_POST['d_pass']."', now())")
or die (mysql_error());
//$add_member = mysql_query($insert);
if (!addNewDealer)
{
echo 'There has been an database error. Please contact the webmaster.' . mysql_error();
}
else
{
///THIS SETS THE SESSION TRACKER CODE********************************************************
//SET SESSION VARIABLES TO PASS BETWEEN PAGES
$dealer_id = mysql_insert_id(); //this would be the dealer_id autoincremented for this dealer row
$_SESSION['trackerID'] = $dealer_id;
}
session_write_close();
echo header("Location: dealerReg2.php" );
}
//THE USER IS DIRECTED TO THE NEXT FORM, TO ENTER ALL OF THE CONTACT INFORMATION AND THE SESSION TRACKERID IS SUPPOSE TO GO WITH IT------------
<?php
session_start();
require "db.php";
//USE THE SESSION GLOBAL FUNCTION TO CALL THE SESSION FROM THE PREVIOUS PAGE
$trackerID = $_SESSION['trackerID'];
//The information is retrieved on this dealerReg2.php form and inserted into the database
if(isset($_POST['submit']))
{
//all the checks and balances for the form - validation - go here
/*INSERT INTO DATABASE ****************ALSO INSERT TRACKER_ID SESSION VARIABLE**************************/
$query = ("INSERT INTO dealerstable (dealer_name, dealer_address, dealer_address2, dealer_city, dealer_state, dealer_country, dealer_zipcode, dealer_Acode, dealer_phone, dealer_AcodeCell, dealer_cell, dealer_AcodeFax, dealer_fax, dealer_contact, dealer_salesContact, dealer_serviceContact, dealer_partsContact, db_password, trackerID)
VALUES ('".$_POST['dealer_name']."', '".$_POST['dealer_address']."', '".$_POST['dealer_address2']."', '".$_POST['dealer_city']."', '".$_POST['dealer_state']."', '".$_POST['dealer_country']."','".$_POST['dealer_zipcode']."', '".$_POST['dealer_Acode']."', '".$_POST['dealer_phone']."', '".$_POST['dealer_AcodeCell']."', '".$_POST['dealer_cell']."', '".$_POST['dealer_AcodeFax']."', '".$_POST['dealer_fax']."', '".$_POST['dealer_contact']."', '".$_POST['dealer_salesContact']."', '".$_POST['dealer_serviceContact']."', '".$_POST['dealer_partsContact']."', '".$_POST['db_password']."', '".$_SESSION['trackerID']."')");
if(!$query)
{
echo "There has been an error creating your account.
Please contact the webmaster." . mysql_error();
}
..................................
/*
1) How do I get the autoincremented id from the dealers table and compare it to the $_SESSION variable to make sure they are equal?
2) How do I pass the $_SESSION variable from page to page, or call it on each page, if it is auto set with session_start()?
3) Once it is passed to the page, can I pass it to the mail() function?
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
by: bportlockPosted on 2009-07-04 at 13:01:51ID: 24777848
1) How do I get the autoincremented id from the dealers table and compare it to the $_SESSION variable to make sure they are equal?
Normally you would do what you have done
$dealer_id = mysql_insert_id(); //this would be the dealer_id autoincremented for this dealer row
$_SESSION['trackerID'] = $dealer_id;
and then in subsequent pages you would use some code like
session_start()
...
... more code
...
if ( ! isset( $_SESSION['trackerId'] ) )
die("Invalid session");
2) How do I call the $_SESSION variable from page to page, if it is auto set with session_start()?
If you have used session_start() then the session variables are available in the array $_SESSION. Just use them.
3) Once it is passed to the page, can I pass it to the mail() function, or do I just pass the variable that I called (see#2)
$_SESSION just contains values - you can pass them to anything you like
4) Then, once the registration page is closed, they check their email and return to LogIn and send a warranty request (through another form), how do I call the original $_SESSION variable, so that the information submitted in this form is "connected" to the same user in the database?
-- after login, they are routed to a loginOptions.php page which gives them three options from which to choose --- warranties, non-warranty part ordering, technical documents page --
How do I make sure the user and the order are connected??
You would normally provide a link that can be clicked on or a hidden field in a form so that when the link is clicked on or the form submitted you can then look for the tracker ID. Your code would look like this
<a href='http://mydomain.com?
or
<form action='.....
<input type='hidden' name='trackerID' value='<?php echo $trackerID; ?>' />
....
and then you could use something like
if ( isset( $_GET['trackerID'] ) )
$rs = mysql_query("select * from table where trackerID='".$_GET['tracke
Now, having said all that I should point out an obvious security hazard. You are using sequential integers so if I get two "orders" from you, numbers 42 and 44, it is obvious that there must have been a number 43 in between. What happens if a craft some HTML to access number 43? It is much safer to use some non-sequential numbering sequence. For instance you could use a random number
$trackerId = mt_rand( 1, 1000000 );
or use an MD5
$trackerId = md5( uniqid( mt_rand(1, 1000000 ) );
and add an extra field in your database to store this value
$addNewDealer = @mysql_query("INSERT INTO dealer_user
(dealer_id,
d_email,
d_pass,
signup_date,
TrackerId )
VALUES
(NULL,
'".mysql_real_escape_strin
'".mysql_real_escape_strin
now(),
'$trackerId'
)"
);
Also, never trust $_POST, $_GET or $_REQUEST - always assume that some will attempt SQL injection and make sure you run them through mysql_real_escape_string first.
See
http://www.php.net/mysql_r
http://www.php.net/uniqid
http://www.php.net/md5