// HTML Submit Test Example
// The following code is used for the Online PDF Form Example 
// the PHP Code for this example: http://www.pdfill.com/example/submit/html_submit_test.php
<?php
// Save the name and value pair into a tab limited excel file 
$xlsString = "Field Name\tField Value\n";

$msg = "<HTML> <HEAD> <TITLE>Add</TITLE> </HEAD> <BODY><p>This is for testing your PDF form only. We don't keep your data into our database.</p>";
$msg .= " <table border= 1 ><tr> <td>Key Names</td> <td>Key Values</td> </tr> ";
echo $msg;

foreach ($_POST as $key => $value)
{

    //Remove slash 
    $value1 = stripslashes($value);
   //Save into excel xls string 
   $xlsString .= "$key\t$value1\n";

   //URL Encode
   $value2 = urlencode($value1);

   //Display to the browser
   echo " <tr> <td>$key </td> <td>$value2</td> </tr>";
}


echo 
"</table> <p>If you see your table of names and values, you may have a working PDF form that you can submit into your database just like HTML Form.</p>
<p><font face=\"Verdana\" size=\"2\"><a style=\"color: blue; text-decoration: underline\" href=\"http://www.pdfill.com\"> PDFill</a> Copyright 2002-2007 by <a style=\"color: blue; text-decoration: underline\" href=\"http://www.plotsoft.com/\">PlotSoft L.L.C</a>..&nbsp; All rights reserved</font></p> 
</BODY></HTML>";
// Create an Excel File based on the time stamp
$time = strval(time());
$excelFileName = "$time.xls"; 
//You can use the email as the file name (you must have a field name 'email')
//$email_value = $_POST['email'];
//$excelFileName = "$email_value.xls"; 

// Write into an excel file
$fp = fopen($excelFileName, "w");   
    fwrite($fp, $xlsString, strlen($xlsString)); 
fclose($fp);
?>


/////////////////////////////////////////////////////////////////////////////
//Some other code may be useful to PHP beginner
//If you know your PDF Form has the following field names, you can get the value directly
$first_name_value = $_POST['first_name'];
$last_name_value = $_POST['last_name'];
$email_value = $_POST['email'];


//Code for sending email for checking 
$message = "First Name: $first_name_value ";
$message .= " Last Name: $last_name_value ";

$mailheaders = "From: Your Name<sale@yourname.com>\n";
$mailheaders .= "Reply-To:sale@yourname.com\n\n";

mail("$email_value", "my email title", $message, $mailheaders);

//Database to store your information from Online PDF Form Submit 
// Step 1: create database connection; substitute your own information
$conn = @mysql_connect("localhost", "my database account", "your password") or die (mysql_error());

// Step 2: select database; substitute your own database name
$db = @mysql_select_db("your own database name", $conn) or die(mysql_error());

//Step 3: Check to see if there is a old order
$sql = "SELECT txn_id FROM customers WHERE txn_id = '$txn_id'";
$sql_result = @mysql_query($sql,$conn) or die (mysql_error());
//Step 4: Update or insert the data
if(mysql_num_rows($sql_result) ==1)
{
   // Update an old record
   $sql = "UPDATE customers SET time_stamp = '$time_stamp', parent_txn_id = '$parent_txn_id', receipt_id = '$receipt_id', quantity = '$quantity', item_name = '$item_name', mc_gross = '$mc_gross', payment_date = '$payment_date', payment_status = '$payment_status', payer_email = '$payer_email', first_name = '$first_name', last_name = '$last_name', address_street = '$address_street', address_city = '$address_city', address_state = '$address_state', address_zip = '$address_zip', address_country = '$address_country' where txn_id = '$txn_id'";
   $sql_result = @mysql_query($sql,$conn) or die (mysql_error());
}
else
{
   //It is empty, need to insert, no matter what result inside
   // Add a new record!
   $sql = "INSERT INTO customers ( txn_id, time_stamp, parent_txn_id, receipt_id, quantity, item_name, mc_gross, payment_date, payment_status, payer_email, first_name, last_name, address_street, address_city, address_state, address_zip, address_country ) VALUES ('$txn_id', '$time_stamp', '$parent_txn_id', '$receipt_id', '$quantity', '$item_name', '$mc_gross', '$payment_date', '$payment_status', '$payer_email', '$first_name', '$last_name', '$address_street', '$address_city', '$address_state', '$address_zip', '$address_country' )";
   $sql_result = @mysql_query($sql,$conn) or die (mysql_error());
}
 
//Display your database information 
// Step 1: create database connection; substitute your own information
$conn = @mysql_connect("localhost", "my database account", "your password") or die (mysql_error());

// Step 2: select database; substitute your own database name
$db = @mysql_select_db("your own database name", $conn) or die(mysql_error());
//Step 3:  Create SQL statement
$sql = "SELECT txn_id, time_stamp, parent_txn_id, address_zip, address_country FROM customers ORDER BY time_stamp DESC";
//Step 4:  execute SQL query and get result
$sql_result = mysql_query($sql, $conn) or die(mysql_error());
//Step 5: format results by row
while ($row = mysql_fetch_array($sql_result)) 
{
   $txn_id = $row['txn_id'];
   $time_stamp = $row['time_stamp'];
   .....
    //use echo to print your information
}

//You can vist here to get php information
http://www.php.net

// How to set up a web server
http://www.apache.org/

//How to add PHP Support for your Web Server
http://www.php.net