简体   繁体   中英

how to use a user input defined in one html page in another php page to fetch data from oracle database

I have one php page which connects to the oracle database and fetches some data based on some user input. Here in this case Once the user will enter the user_id, and submit it, my code will fetch some more data (REQUEST_TIME,WORKFLOW_NAME,EVENT_MESSAGE) of that user. I am running below code and i am not sure if i am doing it correct. I am getting below error:

Warning: oci_execute(): ORA-00904: "USER_ID": invalid identifier in D:\\SVN\\TOOLBOX_WEB\\WEBContent\\admin\\V2\\public\\ssn\\index2.php on line 36

can someone please guide, how to proceed.

This is my php page:

<pre><?php

include('mypage.php');
class logAgent
{
    const CONFIG_FILENAME = "data_config.ini";

    private $_dbConn;
    private $_config;

    function __construct()
    {
        $this->_loadConfig();


        $this->_dbConn = oci_connect($this->_config['db_usrnm'],
            $this->_config['db_pwd'],
            $this->_config['hostnm_sid']);
    }
    private function _loadConfig()
    {
        // Loads config
        $path = dirname(__FILE__) . '/' . self::CONFIG_FILENAME;
        $this->_config = parse_ini_file($path) ;
    }
    public function fetchLogs() {
        $uid =$_POST["USER_ID"];

        $sql = "SELECT REQUEST_TIME,WORKFLOW_NAME,EVENT_MESSAGE
                            FROM AUTH_LOGS WHERE USER_ID = '".$uid."'";

        //Preparing an Oracle statement for execution
        $statement = oci_parse($this->_dbConn, $sql);

        //Executing statement
        oci_execute($statement);
        while (($row = oci_fetch_row($statement)) != false) {
            foreach ($row as $item) {
                echo $item . " ";
            }
            echo "\n";
        }
    }
}
?>

mypage.php

 <!DOCTYPE html> <html> <head> <title>User_Logs</title> </head> <body> <?php if ($_SERVER["REQUEST_METHOD"] == "POST"){ $uid =$_POST["USER_ID"]; $logAgent = new logAgent(); $logAgent->fetchLogs(); } ?> <form method="POST" id="form-add" action="index2.php"> USER_ID: <input type="text" name="USER_ID"/><br> <input type="submit" name="submit" value="Get_Logs"/> </form> </body> </html> 

According to your error, oracle is complaining that it can't find the field USER_ID. Looking at your SELECT statement in the php file, oracle expects that field to be in your AUTH_LOGS table. Check to ensure that you've spelt the name of the field correctly or that the field exists in the table.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM