Solved

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

Posted on 2006-07-19
6
223 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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Wordpress Pagination Function Not working ? 7 28
Intermittent Error on Page Loading 4 55
000webhost.com default error log 1 23
PHP Syntax Error 4 25
Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
This article discusses how to create an extensible mechanism for linked drop downs.
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…
The viewer will learn how to count occurrences of each item in an array.

816 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

8 Experts available now in Live!

Get 1:1 Help Now