Solved

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

Posted on 2006-07-19
6
221 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

743 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now