Hi
I can't find any useful API documentation for Crystal Reports that relates to PHP, but hopefully this will be a pointer:
You can collect the data from the form into a PHP script using the $GET, $POST and $_REQUEST variables. These are associative array's that contain all the data that has been sent with an HTTP request. They are superglobals, so are available at any stage in your script.
You will then be able to pass the data to mssql using mssql_connect(), mssql_query(), and mssql_close().
I am unsure how you would pass data on from PHP to Crystal Reports directly, as I have not been able to find adequate documentation.
Below is some example code which takes the variables sent to the page and inserts them into an MSSQL database. I have used the $REQUEST variable to collect the data in this example, however this should be substituted for $GET or $_POST appropriately, depending on the method you have chosen in your HTML form.
Note that this code is very rough, an can be tidied up considerably, it is only meant as an example. It has been tested with the equivalent MySQL functions, as I do not have an MSSQL server readily available.
This script passes the data from the form to the DB literally (form field name => DB field name). You may wish to do additional data processing.
<?php
// Define the parameters for the SQL server
$SQLServerLocation = '';
$SQLServerUsername = '';
$SQLServerPassword = '';
$SQLDatabaseName = '';
$SQLTableName = '';
// Start building the query
$query = "INSERT INTO `$SQLDatabaseName`.`$SQLTableName` (";
// Loop through the keys sent to the script and add them to the query string
foreach ($_REQUEST as $key => $value) {
$query .= "`$key`,";
}
// Strip off last comma from foreach loop
$query = substr($query,0,-1);
$query .= ") VALUES (";
// Loop through the values sent to the script and add them to the query string
foreach ($_REQUEST as $value) {
$query .= "'$value',";
}
// Strip off last comma from foreach loop
$query = substr($query,0,-1);
$query .= ")";
// Connect to the DB
if (!($mssql = mssql_connect($SQLServerLocation,$SQLServerUsername,$SQLServerPassword))) {
exit("DB Connection Error");
}
// Run the query
if (!mssql_query($query,$mssql)) {
exit(mssql_get_last_message());
}
// Close the DB connection
mssql_close($mssql);
?>