keep oracle connection in main.php form --not working

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sayeediqbal
    New Member
    • Aug 2010
    • 1

    #1

    keep oracle connection in main.php form --not working

    Dear All

    i have two form:
    1) login.php
    2) main.php

    I send info for oracle database login userid and password through login.php and call main.php through submit method.

    in main.php, I am able to connect to oracle database first time on entering main.php main page via Login.php. when i call "query" method it given error not connectd.

    What i want:
    1) the main.php page remain connected to database, untill i disclose the connection.
    2) I might have few other methods, like insert, update in different submit actions in the same page.

    FOLLOWING IS MY CODE OF MAIN.PHP:
    [code=php]<form action="main.ph p" method="POST">
    <div align="center">
    <br><br>
    <input type="text" name=artdescr size="30" value="Enter Art Description!">
    <input type="submit" name="Query" value="Query" />
    </div>
    </form>

    <form action="main.ph p" method="post"
    enctype="multip art/form-data">
    <label for="file">File name :</label>
    <input type="file" name="file" id="file" />
    <br />
    <label for="submit">Up load to Server :</label>
    <input type="submit" name="fload" value="File Load" />
    </form>


    <?php
    session_start() ;
    $_SESSION['uuname'] = $_POST['username'];
    $_SESSION['uupswd'] = $_POST['password'];
    $uid = $_SESSION['uuname'];
    $pwd = $_SESSION['uupswd'];
    $conn=OCI_conne ct($uid, $pwd, "ho");
    ?>

    <?php
    if (isset($_POST['fload']))
    {
    do something;
    }

    if (isset($_POST['Query']))
    {
    $artnono = isset($_REQUEST['artdescr']) ? $_REQUEST ['artdescr'] : '';
    function exe_query ($artnono)
    {
    $stmt = "SELECT art_no, descr, art_grp_no FROM article WHERE descr like $artnono";

    oci_execute($st mt);
    while (ocifetch($stmt ))
    {
    $artno = oci_result($stm t, "ART_NO");
    $artname = oci_result($stm t, "DESCR");
    $grpno = oci_result($stm t, "ART_GRP_NO ");

    // Do something with the data
    echo "Art no:=$artno ";
    echo "Art descr:=$artname ";
    echo "Grp No:=$grpno<br />\n";
    }
    oci_free_statem ent($stmt);
    }
    exe_query($artn ono);
    }

    ?>
    [/code]

    ---
    Regards

    S.Garewal
    Last edited by Atli; Aug 9 '10, 07:44 AM. Reason: Please use [code] tags when posting code examples.
  • Atli
    Recognized Expert Expert
    • Nov 2006
    • 5062

    #2
    You are overwriting the session variables holding the database connection info on each request.

    The $_POST['uname'] element will only be set the first time you enter main.php, from the login.php form. But your code assumes the data from the login.php form will be present each time main.php is executed.

    Consider this:
    [code=php]<?php
    session_start() ;
    $_SESSION['uname'] = $_POST['uname'];
    echo $_SESSION['uname'];
    ?>[/code]
    When you first enter from login.php, the session variable is set and the code echoes it. When you submit your "Query" from the main.php, the $_POST['uname'] variable will NOT be set, but PHP will still set the session variable to it's value, which is nothing.

    What you need to do is check if the $_POST['uname'] is set before copying it's value over to the session. For example:
    [code=php]<?php
    session_start() ;
    if(isset($_POST['uname'])) {
    $_SESSION['uname'] = $_POST['uname'];
    }[/code]
    Now the session value will remain intact in the session until a new uname value is submitted from the login form.

    Comment

    Working...