1

I'm trying to fill a table with a query, but it gives me the error:

Notice: Trying to get property of non-object in [DIRECTORY] on line [LINENUMBER]

(The line points to every instance of $curs)

Heres the how I call the data from the database:

$MyQuery = " //the query that is needed for the data to fill the table
select ndate, code, channel, credit, countedstock, systemstock, discrepancy, nominal 
from mydatabase.stockdiscrepancy
where to_date(ndate,'YYYY-MM-DD') >= to_date('".$from."','YYYY-MM-DD') 
and to_date(ndate,'YYYY-MM-DD') <= to_date('".$to."','YYYY-MM-DD')   
            ";

$curs=$conn->Execute($MyQuery); //parsing the database with the query

So then I tried to do it with a different table to check if its the other codes that are wrong or just the sql query.

Something like this:

select ndate, dealer, location, price 
    from mydatabase.regionalsales
    where to_date(ndate,'YYYY-MM-DD') >= to_date('".$from."','YYYY-MM-DD') 
    and to_date(ndate,'YYYY-MM-DD') <= to_date('".$to."','YYYY-MM-DD')

The site works, the table is filled with the result from the query perfectly.

Then I began to doubt whether its my table that is the problem. But then, I have no idea what is wrong with my table. And so I came here. Heres something about my table, hope this can help:

enter image description here

Is there something wrong with this table? I have checked with several tables and it works, but not this one. Help please, thanks in advance.

pnuts
  • 58,317
  • 11
  • 87
  • 139
soryuken
  • 57
  • 1
  • 8

1 Answers1

0

Comments in oracle are -- or /* ... */ not //, so your query is wrong, change to either

$MyQuery = "-- the query that is needed for the data to fill the table
select ndate, code, channel, credit, countedstock, systemstock, discrepancy, nominal 
from mydatabase.stockdiscrepancy
where to_date(ndate,'YYYY-MM-DD') >= to_date('".$from."','YYYY-MM-DD') 
and to_date(ndate,'YYYY-MM-DD') <= to_date('".$to."','YYYY-MM-DD')   
";

or better, unless you keep a history of the executed queries somewhere and want that comment to show up there:

// the query that is needed for the data to fill the table
$MyQuery = "
select ndate, code, channel, credit, countedstock, systemstock, discrepancy, nominal 
from mydatabase.stockdiscrepancy
where to_date(ndate,'YYYY-MM-DD') >= to_date('".$from."','YYYY-MM-DD') 
and to_date(ndate,'YYYY-MM-DD') <= to_date('".$to."','YYYY-MM-DD')   
";

Inserting values like that is not very safe, a nice question: How can I prevent SQL injection in PHP?

(it is for mysql, but oracle has the same functionalities, e.g. oci_bind_by_name)

Community
  • 1
  • 1
maraca
  • 8,468
  • 3
  • 23
  • 45
  • No man, of course I didnt put the comments like that lol, I wrote those comments when I wrote it in here, so you can safely ignore the comments. – soryuken Nov 20 '15 at 01:33
  • @soryuken ok then remove the where-clause to see if something is wrong with the table, if this works then you might have dates that are not formatted correctly or otherwise illegal. Btw. if you always have the format yyyy-mm-dd you don't need to convert the dates, even NULL is handled the same way. – maraca Nov 20 '15 at 01:57