0

I'm trying to populate a drop down from values in DB on the same page which is from input on the same page itself.

I have tried a few options on the forum but it did not help.

After hitting submit it goes to a next page which is blank.

I have tried onchange=AjaxFunction(); as suggested in one post, but i still get a blank page.

Any help is appreciated.

This is my form.php

<form action="connection.php" class="form-solid-blue" method="get">
   <div class="title">
      <h2></h2>
      <h2>Tracking & Receiving</h2></div>
      <div class="element-input<?php frmd_add_class("input2"); ?>">
         <label class="title"></label>
         <div class="item-cont">
            <input class="small" type="text" name="store" placeholder="Store #"/>
               <span class="icon-place"></span>
         </div>
      </div>
      <div class="element-input<?php frmd_add_class("input"); ?>">
         <label class="title"></label>
            <div class="item-cont">
               <input class="medium" type="text" name="userid" placeholder="UserId"/>
               <span class="icon-place"></span>
            </div>
         </div>
      <div class="element-input<?php frmd_add_class("input1"); ?>">
         <label class="title"></label>
            <div class="item-cont">
               <input class="large" type="text" name="order" placeholder="Order Number"/>
               <span class="icon-place"></span>
            </div>
         </div>
         <div class="submit">
            <input type="submit" value="Send"/>
         </div>
         <div class="element-separator">
            <hr>
            <h3 class="section-break-title">Tracking Numbers</h3>
         </div>
         <div class="element-multiple<?php frmd_add_class("multiple"); ?>">
            <label class="title"></label>
            <div class="item-cont">
               <div class="large">
                  <select data-no-selected="Nothing selected" name="multiple[]" multiple="multiple">

                     <option value="option_1">option 1</option>
                     <option value="option_2">option 2</option>
                     <option value="option_3">option 3</option>
                 </select>
              <span class="icon-place"></span>
           </div>
        </div>
     </div>
     <div class="submit">
        <input type="submit" value="Submit"/>
     </div>
 </form>

This is the connection.php - Server side code

<?php
        // Create connection to Oracle
    $conn = oci_connect("XXXX", "xyxyx", "xyxyx");
    if (!$conn) {
        $m = oci_error();
        echo $m['message'], "\n";
        exit;
    }

    $query = "SELECT TRACKING_NUMBER FROM JC_SHIPPED_ORDER_TRACKING WHERE EXT_PURCHASE_ORDERS_ID = :order_bv";
    $stid = oci_parse($conn, $query);
    $order = $_GET['order'];

    oci_bind_by_name($stid, ':order_bv', $order);
    oci_execute($stid);

   //Because order is a unique value I only expect one row
   $row = oci_fetch_array($stid, OCI_ASSOC);
    if (!$row) {
    exit("The order " . $order . " is invalid. Please check and try again" );
   }
   $trackID = $row['TRACKING_NUMBER'];
   echo "<form name=form1 method=POST action='form.php'>";
    //echo "<select name='TRACKING_NUMBER' onchange=AjaxFunction();>";
    while ($row = oci_fetch_array($stid)) {
    echo "<option value=\"option_1\">" . $row['TRACKING_NUMBER'] . "</option>";


}   
   echo "</select>";
   //echo ("The order " . $order . " is valid.");
   oci_free_statement($stid); 
   oci_close($conn);
?>
11
  • why do you try to create another form in side php file if you want to work in the same form. Commented May 31, 2016 at 19:08
  • @PHJCJO - Thank you for your response. I'm trying to keep the DB connection and queries separate.And I'm trying to populate the dropdown in the form.php Both the input and the result to the dropdown are in form.php Commented May 31, 2016 at 19:19
  • yes i understand it, but i see this line echo "<form name=form1 method=POST action='form.php'>"; in your connection.php, why Commented May 31, 2016 at 19:22
  • @PHJCJO - Not sure if I understand your question correctly. But is this an incorrect way of doing it, or is the syntax incorrect or if something else needs to be added. Commented May 31, 2016 at 19:28
  • yes you can include the connection.php file in the form.php and populate the list, or you can create the class and call to the method that can draw the list on the form.php. but remember you still have to include the class in the form.php. it is not good the good practice to include the connection.php directly in the page though. for you testing it is ok Commented May 31, 2016 at 19:43

1 Answer 1

1

This is the best I can do with the information provided.

in form.php

<select data-no-selected="Nothing selected" name="multiple[]" multiple="multiple">
    <?php require 'path to connection.php'; ?>
 </select>

oh and remove these from connection.php

echo "<form name=form1 method=POST action='form.php'>";

echo "</select>";
Sign up to request clarification or add additional context in comments.

1 Comment

I kept the action blank so that it remains on the same page <form action="" class="form-solid-blue" method="get"> and added the above code. But this time it did not load the form.php at all

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.