libURLFormData and PHP (and MySQL)

Pierre Sahores psahores at easynet.fr
Sat Sep 3 11:36:59 EDT 2005


Hello Nicolas,

See if you can get what you need i cloning this transcript stack's  
form code :

>     set httpheaders to "Content-type: application/x-www-form- 
> urlencoded" & return
>     post "is001=5&is002=" & word 1 of fld "account" of stack  
> "addnewuser" & \
>         "&is003=" & word 1 of fld "password" of stack "addnewuser" & \
>         "&is004=" & word 1 of fld "biblio" of stack "addnewuser" &  
> "&" to url (testurl() & "istream.php")
>     if it is "" then
>       answer "La connexion avec le serveur distant est rompue." &  
> return & \
>           "Vérifiez votre configuration d'accès à l'internet"
>     else if it contains "connection refused" then
>       answer "Le serveur contacté est, provisoirement,  
> indisponible." & return & "Merci de votre compréhension..."
>     else if it contains "bien vouloir en choisir un autre" then
>       answer it
>     else
>       doUsersListView
>       answer "L'utilisateur" && quote & word 1 of fld "account" of  
> stack "addnewuser" & quote && \
>           "a été ajouté à la base des utilisateurs iMire."
>     end if

witch post datas to the below php-rpc brooker :

> <?
>
> // if ($REQUEST_METHOD == POST) {     // PHP < 4.10
> if (!empty($_POST)) {                // PHP >= 4.10
>
>     // $headers = $HTTP_POST_VARS;     // PHP < 4.10
>     $headers = $_POST;                // PHP >= 4.10
>
>     while (list($header, $value) = each($headers)) $exAE .=  
> "$header=$value&";
>     $exAE = urlencode($exAE);
>     $activapp = substr($exAE,0,5);
>
>     if ($activapp == "is001") {
>
>         $connection = fsockopen("localhost", "9482",  & 
> $error_number, &$error_description, "30");
>         if ($connection) {
>             set_socket_blocking($connection, true);
>             fputs($connection,"");
>             fputs($connection,"$exAE"."\r\n");
>             fpassthru($connection);
>             }
>         else     {
>             $connection = fsockopen("localhost", "948",  & 
> $error_number, &$error_description, "30");
>             if ($connection) {
>                 set_socket_blocking($connection, true);
>                 fputs($connection,"");
>                 fputs($connection,"$exAE"."\r\n");
>                 fpassthru($connection);
>             }
>             else print("erreur numÈro $error_number  
> ($error_description)<BR>\n");
>         }
>     }
> }
>
> else print("<HTML><HEAD><TITLE>ERROR: File Not Found</TITLE></HEAD>".
>      "<BODY background='/gif/fond-maison.gif'><H1>File Not Found</ 
> H1><P>".
>      "<H3>The file you have requested does not exist on this  
> server.</H3>".
>      "</BODY></HTML><BR>\n");
>
> ?>

Beside the concept, this method is the one i use since 1997 to bind  
Rev or Web client-side forms to Rev application's servers whose are  
"reading from the php-rpc socket input what they have to do.

Hope this can help. For a more general introduction to this design   
and method, have an eye at the turorial / downloadable example app i  
wrote at : <http://istream.homeunix.com/insead/index_en.html>

Best Regards,

P. Sahores

Le 3 sept. 05 à 15:50, Nicolas Cueto a écrit :

> Hello List,
>
> I'm trying to pass form variables from a stack to
> a MySQL database via a set of PHP pages --
> one page contains an HTML form with a PHP script,
> the other contains the PHP script that receives
> the form variables via an URL request string (?) and
> adds them to the database. (And please don't suggest
> using Rev's sql commands. My webhost only allows
> access to databases via a PHP interface.)
>
> The problem is, I don't see how to use Rev to send
> form variables to a PHP script which usually relies
> on the info being typed into the input fields of the
> HTML form. (The problem, too, is that I've only a
> hazy understanding of PHP and HTML forms.)
>
> Hope that was clear... If it helps any, I've also appended
> below the outlines of the two PHP pages.
>
> Confused yet grateful,
>
> Nicolas Cueto
> niconiko language school
>
>
> ## PHP PAGE FOR ENTERING TYPED DATA ##
> <html> <body>
> <?php
>  // get the id from the URL request
>    $id = $_REQUEST['id'];
>    if( $id ) {   // connect to the server
>       mysql_connect( 'localhost', 'low_test', 'test' )
>          or die( "Error! Could not connect to database: " .
> mysql_error() );
>       // select the database
>       mysql_select_db( 'low_test' )
>         or die( "Error! Could not select the database: " .
> mysql_error() );
>       // retrieve the row from the database
>       $query = "SELECT * FROM `contacts` WHERE `id`='$id'";
>       $result = mysql_query( $query );
>       if( $result && $contact = mysql_fetch_object( $result ) )
>       { // set our variables
>          $lastName = $contact -> lastName;
>          $firstName = $contact -> firstName;
>          $email = $contact -> email;}}
>    // print out the form ?>
> <form action="saveitem.php" method="get">
> <input type="hidden" name="id" value="<?php echo($id) ?>">
>
> <table>
> <tr>
> <th align="left">First Name</th>
> <td align="left">
> <input name="firstName" type="text" value="<?php echo($firstName) ?>"
> />
> </td>
> </tr>
> <snip>
> </table>
>    <br>   <input type="submit" value="Save Entry">   <br>
> </form>
> </body>
> </html>
>
> ### PHP PAGE FOR RECEIVING AND PASSING THE FORM
> ## DATA TO THE DATABASE (a.k.a. "saveitem.php")
> <html>
> <body>
> <?php // saving script
>   // connect to the server
>    mysql_connect( 'localhost', 'username', 'password' )
>       or die( "Error! Could not connect to database: " .
> mysql_error() );
>    // select the database
>    mysql_select_db( 'database_name' )
>       or die( "Error! Could not select the database: " .
> mysql_error() );
>    // get the variables from the URL request string
>    $id = $_REQUEST['id'];
>    $firstName = $_REQUEST['firstName'];
>    $lastName = $_REQUEST['lastName'];
>    $email = $_REQUEST['email'];
>    // if $id is not defined, we have a new entry, otherwise update the
> old entry
>    if( $id )
>    { $query = "UPDATE `contacts` SET `firstName`='$firstName',
> `lastName`='$lastName',
>          `email`='$email' WHERE `id`='$id'"; }
>    else
>    { $query = "INSERT INTO `contacts` (
> `firstName`,`lastName`,`email` )
>          VALUES ( '$firstName','$lastName','$email' )"; }
>    // save the info to the database
>    $results = mysql_query( $query );
>    // print out the results
>    if( $results )
>    { echo( "Successfully saved the entry." ); }
>    else
>    { die( "Trouble saving information to the database: " .
> mysql_error() ); } ?>
> </body>
> </html>
>
> _______________________________________________
> use-revolution mailing list
> use-revolution at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your  
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-revolution

-- 
Bien cordialement, Pierre Sahores

100, rue de Paris
F - 77140 Nemours

skype : psahores

psahores+ at +easynet.fr
sc+ at +sahores-conseil.com

GSM:   +33 6 03 95 77 70
Pro:      +33 1 64 45 05 33
Fax:      +33 1 64 45 05 33

<http://www.sahores-conseil.com/>

WEB/VoD/ACID-DB services over IP
"Mutualiser les deltas de productivité"






More information about the use-livecode mailing list