?
Solved

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

Posted on 2006-07-19
6
Medium Priority
?
229 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
6 Comments
 
LVL 51

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 51

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 51

Accepted Solution

by:
Steve Bink earned 2000 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

Want to be a Web Developer? Get Certified Today!

Enroll in the Certified Web Development Professional course package to learn HTML, Javascript, and PHP. Build a solid foundation to work toward your dream job!

Question has a verified solution.

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

Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
This article discusses how to implement server side field validation and display customized error messages to the client.
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.
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 …
Suggested Courses

762 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