www.webdeveloper.com
Results 1 to 3 of 3

Thread: Pass Form Variable to Another Web Page

Hybrid View

  1. #1
    Join Date
    Apr 2008
    Location
    Seattle, WA
    Posts
    19

    Pass Form Variable to Another Web Page

    I'm trying to create a form in PHP that pulls data from a web service and displays it under the form in XML.

    This project is for my internship and the web service pulls info from a DVD rental company.

    So far my form has one UPC number hard-coded into it and when you click submit you another get one result (see http://mondo247.com/rndb/rndbTEST/xmlEX/index14.php).

    I want to set any UPC number entered into the form (on index14.php) to be passed as a variable into the XML web page (like "<UPC>".$upc."</UPC>" for example) named data14.php.


    My code for both pages is below (everything is real except for the web services URL):

    PHP Code:
    <?php
    //index14.php

    session_start();

    $_SESSION['rnid']='2341';

    $_SESSION['rncert']='5E95798A20D9745B67FAFC3661A3EE5C0C5BDF95';

    $_SESSION['transType']='GETUPCINVENTORY';

    //$_SESSION['upc']='014381501322';
    //$_SESSION['upc'] == $_POST['upc'];
    $_SESSION['upc'] == $upc;

    $_SESSION['itemDetails']='TRUE';

    ?>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <html xmlns="http://www.w3.org/1999/xhtml" lang="en_US" xml:lang="en_US">
        <head>
            <title>XML Data Request</title>
        </head>
    <body>

    <h2>RetailNet Database Test Page from Matt</h2>

    <form  method="post" action="<?php echo $_SERVER['PHP_SELF'?>?go" id="searchForm" name="searchForm">    
        <input type="text" size="20" maxlength="40" name="upc" value="014381501322"  /> &nbsp;&nbsp;<a href="<?=$_SERVER['PHP_SELF']?>">Back to Search Page Start</a>
        <br />
        <input type="submit" id="submit" name="submit" value="Submit" />
    </form>

    <?php
    $queryString 
    $_SERVER["QUERY_STRING"];

    if (
    $queryString == 'go') { ?>

    <?php
    function postHttps($url$request) {
            
    $ch curl_init();
            
    curl_setopt($chCURLOPT_URL$url);
            
    curl_setopt($chCURLOPT_RETURNTRANSFER1);
            
    curl_setopt($chCURLOPT_POST1) ;
            
    curl_setopt($chCURLOPT_POSTFIELDS$request);
            
    curl_setopt($chCURLOPT_SSL_VERIFYPEER0);
            
    curl_setopt($chCURLOPT_SSL_VERIFYHOST0);
            
    $result curl_exec($ch);
            
    curl_close($ch);
            return 
    $result;
    }
    ?>

    <?php
    echo postHttps("https://webservice.exe"utf8_encode(file_get_contents("data14.php")));
    ?>

    <?php ?>

    <br />
    <br />

    </body>
    </html>
    PHP Code:
    <?php
    //data14.php

    session_start();
    ?>

    <?php

    $xml_output 
    "<?xml version=\"1.0\"?>\n";

    $xml_output .= "<TRANSACTION>";

    $xml_output .= "<RNID>2341</RNID>";

    $xml_output .= "<RNCERT>5E95798A20D9745B67FAFC3661A3EE5C0C5BDF95</RNCERT>";

    $xml_output .= "<TRANSACTIONTYPE>GETUPCINVENTORY</TRANSACTIONTYPE>";

    $xml_output .= "<UPC>014381501322</UPC>";

    $xml_output .= "<SHOWITEMDETAILS>TRUE</SHOWITEMDETAILS>";

    $xml_output .= "</TRANSACTION>";

    echo 
    $xml_output;

    ?>
    Thanks for the help!
    Last edited by risingPhoenix; 10-24-2008 at 02:18 AM.

  2. #2
    Join Date
    Dec 2007
    Location
    Auckland, NZ
    Posts
    177
    i am kinda confused but what i think is going wrong is that when you say file_get_contents("data14.php") what you will be getting is the php source the file is not phrase in PHP it is read as a text file.
    if you could do an include so go
    PHP Code:
    include "data14.php";
    echo 
    postHttps("https://webservice.exe"utf8_encode($xml_output)); 
    but you would want to take the session_start() and the echo out.

    Scott.

  3. #3
    Join Date
    Apr 2008
    Location
    Seattle, WA
    Posts
    19

    Talking Mission Complete

    I figured out a solution to my problem by looking at the book "PHP Solutions" by David Powers.

    I completed the web services project by doing the things below:

    1. Create a form that can access a DVD rental company web service (URL) that has DVD info in it

    2. Enter in a DVD UPC number into the form

    3. Click "Submit" and XML is outputted onto the same web page under the form

    The hard part is over. Yaaayyy!!!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles