Solved

Capturing and Storing 3rd party order form parameters into php and store into mysql...

Posted on 2006-07-19
6
224 Views
Last Modified: 2008-02-26
I am interested in setting up code to store order form variables passed back to my site from my 3rd party shopping cart and being new, I don't know how.  Here are the parameters I wish to capture.  Please show me the php code that will enable me to get and store the database into the database.  thanks.

order_number
card_holder_name
street_address  
city  
state  
zip  
country
email  
phone  
credit_card_processed  
total  
product_id  
quantity  
product_description
0
Comment
Question by:jwlevin
  • 3
6 Comments
 
LVL 50

Expert Comment

by:Steve Bink
ID: 17142218
You want to receive a form submission from another site, and store that information in your database, correct?

Remember, the $_POST superglobal will show you the form fields submitted.  If they are using the GET method, then $_GET will have them.  I recommend you use the POST method with this, if possible.

Here's the flowchart of what you need to do:

<?
$username = ''; // put your db username here
$password = ''; // put your db password here
$hostname = ''; // put your db hostname here

if (!($myconnection = mysql_query($hostname, $username, $password))) {
  // no connect....die/handle the error
}

$dbname = ''; // put your db name here
mysql_select_db($dbname, $myconnection);

// now you have a good connection generate your query
$query = "INSERT INTO MyTable (field1, field2, example, city, state) VALUES (" .
    "'${_POST['field1']}', '${_POST['field2']}', '${_POST['example']}', '${_POST['city']}', '${_POST['state']}')";

//run the query
if (!($result = mysql_query($query, $myconnection))) {
  // query did not work...handle the error?
}
0
 
LVL 50

Expert Comment

by:Steve Bink
ID: 17142240
There are other steps, such  as verifying the data you are receiving, parsing text fields to prevent SQL injection attacks, etc.  Handle all of that at some point before your query.  The query formulation uses a particular syntax...here's another, functionally equivalent line:

$query= "INSERT INTO MyTable (field1, field2, example, city, state) VALUES (" .
    "'" . $_POST['field1'] . "', " .
    "'" . ${POST['field2'] . "'', " .
    "'" . $_POST['example'] . "', " .
    "'" . $_POST['city'] . ", " .
    "'" . $_POST['state'] . "')";
0
 

Author Comment

by:jwlevin
ID: 17143073
Where should this code go?  I am capturing the info from another site that sends me the parameters.  How do I call the script?  I am an extreme novice wihen it comes to this, so when you explain it, assume I know nothing.  

1.  Where does the code go?
2.  What do I put where?
0
 
LVL 50

Accepted Solution

by:
Steve Bink earned 500 total points
ID: 17143916
When the other site sends you the parameters, it will be sending them to a particular URL.  For example, in their form, you might see this:

<form action="http://your.domain.com/formreceipt.php" method="get">

So now you make a page called formreceipt.php in your document root, and code it to do what you need.  If you are new to PHP, I would recommend you bookmark the online manual.  It makes things A LOT easier.  :)

http://www.php.net/manual/en/


0

Featured Post

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question