Oracle&PHP drop down box?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
cupramen
Forum Newbie
Posts: 5
Joined: Fri Apr 17, 2009 12:55 pm

Oracle&PHP drop down box?

Post by cupramen »

Hi i am a novice in php and have been trying to figure this problem out by myself, i want to populate data from my database into a drop down box using php, i have been looking all over the web and can only find examples for mysql not oracle and desperately need help this is what i already have.

Code: Select all

<form action="<?php echo $_SERVER['PHP_SELF'];?>" method="post">
 
 <?php
 
         $c = @oci_connect('hr', 'hr)
          or die("Could not connect to Oracle server");
 
   $flight_number = oci_query("SELECT * FROM flight_schedules");
   echo "<select name="flight_number"><option value="0"></option>";
   while($row=oci_fetch_assoc($flight_number)){
   extract($row);
   echo "<option value="$flight_number">$flight_number</option>";
   }
   echo "</select>";
 ?>]
 
</form>
i tried to modify mysql php code into oracle php code but i get this error message

Parse error: parse error, expecting `','' or `';'' in C:\Apache\Apache2\htdocs\project\fliename.php on line 12

if anyone can help me it would fantastic
cupramen
Forum Newbie
Posts: 5
Joined: Fri Apr 17, 2009 12:55 pm

Re: Oracle&PHP drop down box?

Post by cupramen »

Thank you for replying and i used your code, there are no errors however the drop down box has no vaules in them

Code: Select all

   <?php
   $c = oci_connect('hr', 'hr')
        or die('Could not connect to Oracle server');
 
    $stmt = oci_parse($c, 'SELECT flight_number FROM flight_schedules');
   oci_execute($stmt, OCI_DEFAULT);
    ?>
    <form action="test2.php" method="post">
       <select name="flight_number">
            <option value="0"></option>
           <?php
          while (oci_fetch($stmt)) {
               printf('<option value="%1$s">%1$s</option>'
                    , oci_result($stmt, 'flight_number'));
          }
          ?>
       </select>
   </form>
maybe i should have shown what i orignally had planned to do

Code: Select all

<form action="<?php echo $_SERVER['PHP_SELF'];?>" method="post">
 
 <?php
 
    $stmt = oci_parse($c, 'select flight_number from flight_schedules');
   oci_execute($stmt, OCI_DEFAULT);
?>
 
 
       <select name="flight_number">
            <option value="0"></option>
           <?php
          while (oci_fetch($stmt)) {
               printf('<option value="%1$s">%1$s</option>'
                    , oci_result($stmt, 'flight_number'));
          }
          ?>
       </select>
 
 
   <p>
  Flight Number:<br />
   <input type="text" name="flight_number" size="30" maxlength="30" value="" />
    </p>
     <p>
  Airline Code:<br />
   <input type="text" name="airline_code" size="30" maxlength="30" value="" />
     </p>
      <p>
  Departing From:<br />
   <input type="text" name="departing_from" size="30" maxlength="30" value="" />
    </p>
     <p>
  Arriving To:<br />
   <input type="text" name="arriving_to" size="30" maxlength="30" value="" />
     </p>
      <p>
  Airport Departing:<br />
   <input type="text" name="airport_departing" size="30" maxlength="30" value="" />
    </p>
     <p>
  Terminal Departing:<br />
   <input type="text" name="terminal_departing" size="30" maxlength="30" value="" />
     </p>
      <p>
  Airport Arriving:<br />
   <input type="text" name="airport_arriving" size="30" maxlength="30" value="" />
    </p>
     <p>
  Terminal Arriving:<br />
   <input type="text" name="terminal_arriving" size="30" maxlength="30" value="" />
     </p>
      <p>
  Date Departing:<br />
   <input type="text" name="dat_departing" size="30" maxlength="30" value="" />
    </p>
     <p>
  Date Arriving:<br />
   <input type="text" name="date_arriving" size="30" maxlength="30" value="" />
     </p>
      <p>
  Time Departing:<br />
   <input type="text" name="time_departing" size="30" maxlength="30" value="" />
    </p>
     <p>
  Time Arriving:<br />
   <input type="text" name="time_arriving" size="30" maxlength="30" value="" />
     </p>
      <p>
 
   <input type="submit" name="submit" value="Submit!" />
     </p>
      <p>
   <INPUT TYPE="reset" VALUE="Clear">
     </p>
     <a href = "test.html"> Menu</a>
 
 
</form>
What i wanted was to replace all or most of the textboxes with drop down boxes and the query would be displayed by this other php file

Code: Select all

<?php
 
         if (isset($_POST['submit']))
 
{
 
         $c = @oci_connect('hr', 'hr')
          or die("Could not connect to Oracle server");
 
 
        $flight__number = $_POST['flight_number'];
        $airline_code = $_POST['airline_code'];
        $departing_from = $_POST['departing_from'];
        $arriving_to = $_POST['arriving_to'];
        $airport_departing = $_POST['airport_departing'];
        $terminal_departing = $_POST['terminal_departing'];
        $airport_arriving = $_POST['airport_arriving'];
        $terminal_arriving = $_POST['terminal_arriving'];
        $date_departing = $_POST['date_departing'];
        $date_arriving = $_POST['date_arriving'];
        $time_departing = $_POST['time_departing'];
        $time_arriving = $_POST['time_arriving'];
 
 
 
         $s = oci_parse($c, "INSERT INTO flight_schedules(flight_number, airline_code, departing_from,
                       arriving_to, airport_departing, terminal_departing, airport_arriving, terminal_arriving,
                       date_departing, date_arriving, time_departing, time_arriving)
                       vALUES('$flight_number', '$airline_code','$departing_from', '$arriving_to',
                       '$airport_departing', '$terminal_departing','$airport_arriving', '$terminal_arriving',
                       '$date_departing', '$date_arriving','$time_departing', '$time_arriving',)");
             $result = oci_execute($s);
 
 
          if ($result)
   {
 
         echo "<p>A New Airline has been inserted</p>";
          oci_commit($c);
   }
         else
      {
         echo "<p>There was a problem inserting a New Airline!</p>";
          var_dump(oci_error($s));
      } 
         oci_close($c);
 
}
 
include "insert_flight_schedules.php";
include "flight_schedules_query.php";
 
?>
cupramen
Forum Newbie
Posts: 5
Joined: Fri Apr 17, 2009 12:55 pm

Re: Oracle&PHP drop down box?

Post by cupramen »

If you haven't already found it, there is Oracle tutorial section called "Creating an Application Using PHP" at http://st-curriculum.oracle.com/tutoria ... /index.htm that might have some useful information.
Thank You McInfo even though i still have not found the soultion to my problem, i have been having problems with a login page and this has given me a step in the right direction however now i do not know how to use data from database as the username and password, lol more problems :banghead:
cupramen
Forum Newbie
Posts: 5
Joined: Fri Apr 17, 2009 12:55 pm

Re: Oracle&PHP drop down box?

Post by cupramen »

Okay i have been looking around the interent and tried to use change mysql examples and have three drop down menus that work but they do not display the values from the database in the drop down menu, heres my code for all three of them.

Code: Select all

<form action="<?php echo $_SERVER['PHP_SELF'];?>" method="post">
 
  <p>Search for a flight with a maximum price.</p>
   <p>
  Flight Price:<br />
   <input type="text" name="flight_price1" size="20" maxlength="20" value="" />
    </p>
 
   <input type="submit" name="submit1" value="Submit"/>
   <input type="reset" VALUE="Clear"></p>
    </p>
     <a href = "test.html"> Menu</a>
<p>
 
<?php
 
 
                 $conn = oci_connect(hr, hr)
                 or die("Can't connect to database server!");
 
 
 
$query = "SELECT flight_price FROM flight_costs"; 
$result = oci_parse($conn, $query) or die(oci_error() . "<br>$query");
oci_execute ($result);
?>
 
<select name="flight_price"> 
 
<?php  
while ($row = oci_fetch_array($result)) {  
    echo "<option value=\"" . $row['flight_price'] . "\">" . $row['flight_price'] . "</option>\n";  
} 
 
?> 
 
</select> 
 

Code: Select all

 
    <?php
    $c = oci_connect('hr', 'hr')
        or die('Could not connect to Oracle server');
    $stmt = oci_parse($c, 'SELECT flight_price FROM flight_costs');
    oci_execute($stmt);
 
    ?>
    <form action="index.php" method="post">
        <select name="flight_price">
           <option value="0"></option>
           <?php
          while (oci_fetch($stmt)) {
      $price  = $row['flight_price'];
               printf('<option value="$price"></option>'
                     , oci_result($stmt, 'flight_price'));
           }
           ?>
       </select>
   </form>

Code: Select all

<?php
 
                 $conn = oci_connect('hr', 'hr')
                 or die("Can't connect to database server!");
 
       // create SQL statement
       $query = "SELECT flight_price FROM flight_costs";
    
 
// execute SQL query and get result
               $result = oci_parse($conn, $query);
               oci_execute ($result);
 
// put data into drop-down list box
while ($row = oci_fetch_row($result)) {
    $price  = $row['flight_price'];
    $option_block .= "<OPTION value=\"$price\">$price</OPTION>";
}
 
oci_close($conn);
 
?> 
 
 
<select name="flight_number">
<?php echo "$option_block";?>
</select>
 
</form>
Each one of these do not display the data from my oracle database but instead have white spaces instead
Post Reply