Creating the PHP file
You will be unable to use the original script to retrieve data from the database as the HTTP_POST_VARS functions are only able to import post data and cannot send information back to the publication.
To send information back to the publication, you will need to pull the records from the database into an array (using the
mysql_fetch array() function), assign each of the strings to an index of the returned array, then issue name-value pairs using the echo function. For example:
Code:
<?php
$DBhost = "localhost";
$DBuser = "username";
$DBpass = "password";
$DBName = "mydb";
$connect = mysql_connect($DBhost,$DBuser,$DBpass);
$db = mysql_select_db($DBName,$connect);
$query = "SELECT * FROM employees";
$result = mysql_query($query, $connect);
$row = mysql_fetch_array($result );
$data = "&first=".$row['first']."&last=".$row['last']."&address=".$row['address']."&position=".$row['position'];
echo $data
?>
You will again need to ensure that the
username and
password values on lines 4 and 5 are changed to a user who has read/write access to the 'mydb' database.
Now save this file in the document root of your web server with the file name
select.php.
Creating the Opus publication
Now launch Opus, create a blank new publication and perform the following steps:
- Add four text boxes (not input boxes) to the page
- Right-click on the first text box and select
Insert Variable, then create a new variable named
first with a default blank text value
- Insert a variable named
last (again with a default blank text value) into the second text box
- Insert variables named
address and
position into the third and fourth boxes respectively
- Now right-click on the page and select
Edit Actions
- Apply an
On Show trigger followed by a
Post Web Data action
- In the URL field, type in your domain name followed by a forward slash and the file name
select.php. For example,
http://www.digitalworkshop.com/select.php or if the web server is running on the local machine
http://localhost/select.php
- Select the
Destination tab and enable the
Multiple Fields option
- Click the
Add button four times to create four strings
- Rename each of the strings to match the variable names,
first,
last,
address and
position
- Open the drop-down menus to the right of the strings and assign each string to the corresponding variable (for example, assign the string
first to the variable
first)
- Click Apply and OK
Now preview the publication. The first records from the database should be displayed in the text boxes.