Digital Workshop

Welcome to the Digital Workshop Message Boards
It is currently December 22nd, 2024, 6:43 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 7 posts ] 
Author Message
 Post subject: Post Web Data - Part 1: Adding records to a database
PostPosted: May 4th, 2005, 11:08 am 
Offline

Joined: October 25th, 2004, 12:27 pm
Posts: 526
Location: Digital Workshop
Opus web publications and Flex publications are unable to communicate with database using the standard Database Query actions (which rely on ODBC drivers). However, it is possible to use Post Web Data actions in conjunction with PHP or ASP script files to send and retrieve data from a database on the web server.

The following steps will show you how to set up a MySQL database on the web server, create a PHP file which will write records to this database and produce an Opus publication which will send this information to the PHP file.

Testing the PHP and MySQL installations

This procedure assumes that PHP 4.x and MySQL are installed and correctly configured on your web server. To test this, simply create a file in Notepad containing the following script:

Code:
<?php phpinfo() ?>


and save this file in the document root of your webserver (this is the htdocs folder on an Apache web server or the wwwroot folder on an IIS web server) with the name test.php. Once saved, please open your browser and navigate to the address http://webserver/test.php (where webserver is the IP address or domain name of your web server or localhost if the web server is running on the local machine).

If PHP is correctly installed, an information page should appear listing version numbers and installed modules. To confirm whether your PHP installation supports connections to MySQL databases, simply scroll down this list and look for a table named mysql or mysqli. Please also ensure that the MySQL service is running on the web server (this is usually indicated by a green traffic light icon in the system tray or you can run the services.msc applet from the Run command to check if this service is installed and running).

Creating the MySQL database

All being well, please use a graphical front-end (such as MySQL Administrator or phpMyAdmin) or the command line to create a new MySQL database (sometimes called a schema) named mydb. In this database, create a new table named employees containing the following four fields:

first - set this to data type varchar(25)
last - set this to data type varchar(25)
address - data type varchar(255)
position - data type varchar(50)

In real-world situations, you would probably want to add an auto-incrementing primary key as the first field of this database so that each record has a unique numerical record, but this is not necessary for this example.

Creating the PHP file

Now launch Notepad and insert the following script commands:

Code:
<?php

$first = $HTTP_POST_VARS['first'];
$last = $HTTP_POST_VARS['last'];
$address = $HTTP_POST_VARS['address'];
$position = $HTTP_POST_VARS['position'];

$DBhost = "localhost";
$DBuser = "username";
$DBpass = "password";
$DBName = "mydb";

$connect = mysql_connect($DBhost,$DBuser,$DBpass);
$db = mysql_select_db($DBName,$connect);
$query = "INSERT INTO employees (first, last, address, position) VALUES ('$first','$last','$address','$position')";
$result = mysql_query($query, $connect);

?>


Please replace localhost with the address of the database server (or leave it as localhost if the server is running on the local machine), replace username with a user who has access to the mydb database (for example, root) and replace password with the password for this user (by default, the root user's password is blank, but you may have altered this in the MySQL configuration).

Now save this document in the document root of your web server with the file name insert.php.

Creating the Opus publication

Now create a new publication in Opus and add four text input fields to the page. Set the first input field to store information into a new variable named first, the second to a variable named last, the third to a variable named address and the final field to store information into a variable named position (all of these variables should be to publication variable with an initial blank text value).

Now add a button to the page and apply a Post Web Data action. As we want the Opus publication to be the source of the data, select the Source tab. In the URL field, input the address to the insert.php file on your web server (if the server is running on the local machine, this will probably be http://localhost/insert.php)
Select the Multiple Fields option, then click the Add button four times to create four parameters and rename the parameters to first, last, address and position respectively. Now open the drop-down menu to the right of each parameter and select the corresponding variable from the list. The screen should now resemble the following:

Image

Click Apply and OK to confirm the changes.

Now preview the publication, input some information into each of the fields and click the button to post the data.

You can now check that the data has been added to the table using phpMyAdmin, MySQL Query Browser or launching a mysql command prompt and issuing the command:

Code:
SELECT * FROM employees;


This should confirm that the inputted data was successfully written to the database.


For this message Robin Garrett has been thanked by : mackavi


Last edited by Robin Garrett on May 8th, 2005, 12:56 am, edited 1 time in total.

Top
 Profile Visit website  
 
 Post subject: thanks !!!!!!!!!!!
PostPosted: May 4th, 2005, 6:58 pm 
Offline

Joined: March 31st, 2005, 10:53 am
Posts: 7
:lol: this is what we're loking for!

Greetings Koen


For this message koen2 has been thanked by : mackavi


Top
 Profile  
 
 Post subject: What's the problem?
PostPosted: July 2nd, 2005, 8:18 am 
Offline

Joined: March 31st, 2005, 10:53 am
Posts: 7
Hi Robin,

I have read your tutorial more then twenty times, made my MySQL database working on the internet. Put the insert.php on my website and all other stuff.

But? .. No results. According to my php-friends there's nothing wrong with the script (seems logical since you've wrote it) but where do I have to look for the error?

Can you help me?

Greetings Koen


Attachments:
insert.txt [480 Bytes]
Downloaded 3332 times
testphp.imp [20.83 KiB]
Downloaded 3261 times


For this message koen2 has been thanked by : mackavi
Top
 Profile  
 
 Post subject: No data is posting
PostPosted: November 10th, 2005, 5:44 am 
Offline

Joined: August 24th, 2005, 8:48 pm
Posts: 3
I followed all the steps in the tutorial and I could not get the data to post.

what are the common mistake that stops the success of the process.

Regards

joe


For this message jorous has been thanked by : mackavi


Top
 Profile  
 
 Post subject:
PostPosted: November 14th, 2005, 12:16 pm 
Offline

Joined: November 9th, 2004, 10:35 am
Posts: 49
Location: Canterbury UK
Some hosts do not allow remote access to the database servers, have you tried converting to a flash publication and putting this on the server to test?

_________________
Andy
Hayward Design
E: andy@hayward-design.co.uk
T: 01227 721864

Opus Professional Version v6.00
Build Date Jun 18 2007 15:01:07
Windows XP Professional - Build 2600 Service Pack 2
Total Memory 1024 Mb
DirectX Version 9.0 or better
AMD Athlon


For this message Andy Piddock has been thanked by : mackavi


Top
 Profile Visit website  
 
 Post subject:
PostPosted: November 14th, 2005, 4:04 pm 
Offline

Joined: November 9th, 2004, 10:35 am
Posts: 49
Location: Canterbury UK
Hi Joseph,

if you go directlty to your php script url http://nlpuae.net/insert.php you get this error. I think you need to check your connection info, user & password?

Warning: mysql_connect(): Access denied for user: 'anne@localhost' (Using password: YES) in /home/nlpuaene/public_html/insert.php on line 13

Warning: mysql_select_db(): supplied argument is not a valid MySQL-Link resource in /home/nlpuaene/public_html/insert.php on line 14

Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in /home/nlpuaene/public_html/insert.php on line 16

_________________
Andy
Hayward Design
E: andy@hayward-design.co.uk
T: 01227 721864

Opus Professional Version v6.00
Build Date Jun 18 2007 15:01:07
Windows XP Professional - Build 2600 Service Pack 2
Total Memory 1024 Mb
DirectX Version 9.0 or better
AMD Athlon


For this message Andy Piddock has been thanked by : mackavi


Top
 Profile Visit website  
 
 Post subject: IT DOES WORK WITH FLEX AND IT DOES WORK WITH PROFESSIONAL
PostPosted: November 15th, 2005, 9:52 am 
Offline

Joined: March 31st, 2005, 10:53 am
Posts: 7
Hi Everybody,

It took me to long, I have been asking at least twenty people. But now Albert (Holland) gave me the tip!

The posting doen't seem to work in FLEX-publications! But when you put them on-line (on your webserver) they do!
And it works great in Professional-publications


For this message koen2 has been thanked by : mackavi


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 13 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group