libURLFormData and PHP (and MySQL)

Dave Cragg dcragg at lacscentre.co.uk
Sun Sep 4 10:42:57 EDT 2005


On 3 Sep 2005, at 14:50, Nicolas Cueto wrote:

> 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.)
>


> ### 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>

Hi Nicolas

  I don't know PHP, but it looks like the PHP script expects 4 form  
items named id, firstName, lastName and email.

In your script, try something like the following:

  put "abc123" into tID
  put "Cueto" into tLastName
  put "Nicolas" into tFirstName
  put "whatever at wherever.com" into tEmail

put libUrlFormData("id", tID, "firstName", tFirstName, "lastName",  
tLastName, "email", tEmail) into tForm

put "http://whatever.com/saveitem.php" into tUrl

## if using GET

put "?" & tForm after tUrl
get url tUrl

## if using POST

post tForm to url tUrl

Cheers
Dave






More information about the use-livecode mailing list