Can't use Get Method in PHP - php

i'm not good enough at english and PHP. So I have a question: How to get result by 'GET' request?
i have an url like this:
laporanpemesanancetak.php?TANGGAL_PERIODE1=2016-05-01&TANGGAL_PERIODE2=2016-05-23
and my GET method like:
if (isset($_GET["$TANGGAL_PERIODE1"])) {
$TANGGAL_PERIODE1 = $_GET["TANGGAL_PERIODE1"];
$TANGGAL_PERIODE2 = $_GET["TANGGAL_PERIODE2"];
$query = mysql_query("select p.PURCHASE_ORDER_PEMESANAN,p.TANGGAL_PEMESANAN,s.NAMA_SUPPLIER,i.NAMA_BAHAN_BAKU,p.JUMLAH_PEMESANAN,i.SATUAN,k.NAMA_KARYAWAN
from pemesanan p,supplier s,inventori i,karyawan k
where p.NPWP_SUPPLIER = s.NPWP_SUPPLIER and p.ID_BAHAN_BAKU = i.ID_BAHAN_BAKU and p.NIP_KARYAWAN = k.NIP_KARYAWAN and p.TANGGAL_PEMESANAN between '$TANGGAL_PERIODE1' and '$TANGGAL_PERIODE2' order by p.PURCHASE_ORDER_PEMESANAN");
while ($row = mysql_fetch_array($query)) {
$pdf->Cell(27,8,$row["PURCHASE_ORDER_PEMESANAN"],1,0,"C");
$pdf->Cell(27,8,$row["TANGGAL_PEMESANAN"],1,0,"C");
$pdf->Cell(27,8,$row["NAMA_SUPPLIER"],1,0,"C");
$pdf->Cell(27,8,$row["NAMA_BAHAN_BAKU"],1,0,"C");
$pdf->Cell(27,8,$row["JUMLAH_PEMESANAN"],1,0,"C");
$pdf->Cell(27,8,$row["SATUAN"],1,0,"C");
$pdf->Cell(27,8,$row["NAMA_KARYAWAN"],1,0,"C");
$pdf->Ln();
}
}
and the result is show nothing, i've tried using
if (isset($_GET["$TANGGAL_PERIODE1"])&&$_GET["$TANGGAL_PERIODE2"])
but the result is same, i've tried my sql query into mysql and it works.
Can someone help me please? it would be great :)

$_GET["$TANGGAL_PERIODE1"]
Note the $ in the key. This will try to evaluate the variable $TANGAL_PERIODE1 rather than look a key of the $_GET array named TANGAL_PERIODE1
Be sure to not ignore E_NOTICE and E_WARNING messages when developing. These are important clues, this would generate a notice of an undefined variable.

Related

PHP SQLite - prepared statement misbehaves?

I have the following SQLite table
CREATE TABLE keywords
(
id INTEGER PRIMARY KEY,
lang INTEGER NOT NULL,
kwd TEXT NOT NULL,
count INTEGER NOT NULL DEFAULT 0,
locs TEXT NOT NULL DEFAULT '{}'
);
CREATE UNIQUE INDEX kwd ON keywords(lang,kwd);
Working in PHP I typically need to insert keywords in this table, or update the row count if the keyword already exists. Take an example
$langs = array(0,1,2,3,4,5);
$kwds = array('noel,canard,foie gras','','','','','');
I now these data run through the following code
$len = count($langs);
$klen = count($kwds);
$klen = ($klen < $len)?$klen:$len;
$sqlite = new SQLite3('/path/to/keywords.sqlite');
$iStmt = $sqlite->prepare("INSERT OR IGNORE INTO keywords (lang,kwd)
VALUES(:lang,:kwd)");
$sStmt = $sqlite->prepare("SELECT rowid FROM keywords WHERE lang = :lang
AND kwd = :kwd");
if (!$iStmt || !$sStmt) return;
for($i=0;$i < $klen;$i++)
{
$keywords = $kwds[$i];
if (0 === strlen($keywords)) continue;
$lang = intval($langs[$i]);
$keywords = explode(',',$keywords);
for($j=0;$j < count($keywords);$j++)
{
$keyword = $keywords[$j];
if (0 === strlen($keyword)) continue;
$iStmt->bindValue(':kwd',$keyword,SQLITE3_TEXT);
$iStmt->bindValue(':lang',$lang,SQLITE3_INTEGER);
$sStmt->bindValue(':lang',$lang,SQLITE3_INTEGER);
$sStmt->bindValue(':kwd',$keyword,SQLITE3_TEXT);
trigger_error($keyword);
$iStmt->execute();
$sqlite->exec("UPDATE keywords SET count = count + 1 WHERE lang =
'{$lang}' AND kwd = '{$keyword}';");
$rslt = $sStmt->execute();
trigger_error($sqlite->lastErrorMsg());
trigger_error(json_encode($rslt->fetchArray()));
}
}
which generates the following trigger_error output
Keyword: noel
Last error: not an error
SELECT Result: {"0":1,"id":1}
Keyword: canard
Last Error: not an error
SELECT Reult:false
Keyword:foiegras
Last Error: not an error
SELECT Result: false
From the SQLite command line I see that the three row entries are present and correct in the table with the id/rowid columns set to 1, 2 and 3 respectively. lastErrorMsg does not report an error and yet two of the three $rslt->fetchArray() statements are returning false as opposed to an array with rowid/id attributes. So what am I doing wrong here?
I investigated this a bit more and found the underlying case. In my original code the result from the first SQLite3::execute - $iStmt-execute() - was not being assigned to anything. I did not see any particular reason for fetching and interpreting that result. When I changed that line of code to read $rslt = $iStmt->execute() I got the expected result - the rowid/id of the three rows that get inserted was correctly reported.
It is as though internally the PHP SQLite3 extension buffers the result from SQLiteStatement::execute function calls. When I was skipping the assignment my next effort at running such a statement, $sStmt->execute() was in effect fetching the previous result. This is my interpretation without knowing the inner workings of the PHP SQLite3 extension. Perhaps someone who understands the extension better would like to comment.
Add $rslt = NONE; right after trigger_error(json_encode($rslt->fetchArray())); and the correct results appear.
FetchArray can only be called once and somehow php is not detecting that the variable has changed. I also played with changing bindValue to bindParam and moving that before the loop but that is unrelated to the main issue.
It is my opinion that my solution should not work unless there is a bug in php. I am too new at the language to feel confident in that opinion and would like help verifying it. Okay, not a bug, but a violation of the least surprise principle. The object still exists in memory so without finalizing it or resetting the variable, fetch array isn't triggering.

SOAP API / SQL Error "ORA 00904 invalid Identifier"

I have the following problem:
I need to get a few columns of a oracle db table to display information on a .php page. To do this, I'm using a SOAP-API, which works flawlessly with any other table, only not with this one.
This is the Code I am using for all of these Queries:
$setSearchObjectsIn = new SearchObjectsInType();
$setSearchObjectsIn->sessionId = (String) $sessionId;
$setSearchObjectsIn->table = (String) 'STFCFG_DD_VALUE';
$setSearchObjectsIn->caseSensitive = (String) 'false';
$setSearchObjectsIn->limitedResult = (String) 'false';
$setSearchObjectsIn->restrictions[0]['attributeName']= (String) 'STFCFG_DD_VALUE.DDID';
$setSearchObjectsIn->restrictions[0]['restriction']['operator'] = (String) '=';
$setSearchObjectsIn->restrictions[0]['restriction']['value'] = (String) $ddid;
$setSearchObjectsIn->resultColumns[0] = (String) 'STFCFG_DD_VALUE.DD_VALUE';
$setSearchObjectsIn->resultColumns[1] = (String) 'STFCFG_DD_VALUE.CATALOG_NAME';
$setSearchObjectsIn->resultColumns[2] = (String) 'STFCFG_DD_VALUE.MSG_ID';
$client = new SoapClient((String) $instance.'/axis/services/GenericApiWS?wsdl');
$result = $client->searchObjects($setSearchObjectsIn);
And this is the Error I get with this special table:
ORA-00904: "MAN_ID": ungültiger Bezeichner
I have also tried starting this query with SoapUI, which results in the exactly same thing.
The fact, that I have nothing like "MAN_ID" in my code has me wondering, as the error looks like I would query a column named like that, which I obviously don't do. (There is also no column "MAN_ID" in the requested table, so I have no idea where this comes from)
I hope you can help me
I'd try looking for MAN_ID in the SOAP server code - the error may be what the server returns and it may be looking for that column implicitly. The error message is definitely produced by Oracle, so search the way your query gets there and if possible, see what query gets executed.

Pass By Reference to COM Object in PHP

So I'm hoping someone can help and I'm sure this is probably something simple I'm missing. I'm using PHP to access a .net API for a third party software.
Based on the very minimalist documentation on the API I have a working vbsript that connects to the object, performs a login and then does a query which results in the output of the query being dumped to a message box.
Here's the vbscript sample:
'Test device status
Set xxx = CreateObject("The.API.Object.Goes.Here")
'Login
Result = Xxx.LoginToHost("xxx.xxx.xxx.xxx","8989","Administrator","")
if (Result = true) then
MsgBox("OK")
else
MsgBox("Error - " & Xxx.LastError)
WScript.Quit
end if
'Get Status
Result = Xxx.GetDeviceStatus("", out)
if (Result = true) then
MsgBox(out)
else
MsgBox("Error - " & Xxx.LastError)
end if
'Logout
Result = Xxx.Logout()
if (Result = true) then
MsgBox("Logout OK")
else
MsgBox("Error - " & Xxx.LastError)
end if
The Xxx.GetDeviceStatus has two perimeters, the first being a device target or if left blank returns all devices, the second is the string variable to dump the result in.
When the script executes, the second message box contains a list of all devices as I would expect.
In PHP I have:
$obj = new DOTNET("XxxScripting, Version=1.0.XXXX.XXXXXX, Culture=neutral, PublicKeyToken=XXXXXXXXXXXXXXXX","Here.Goes.The.Api");
$obj->LoginToHost('xxx.xxx.xxx.xxx','8989','Administrator','');
$result = $obj->GetDeviceStatus('','out');
echo $result."<br />";
echoing result gives 1 because the value of result is a boolean value and GetDeviceStatus is successful. What I can't figure out is how to get the value of 'out' which is the actual query result.
Any help would be greatly appreciated.
The second parameter of GetDeviceStatus() method call according to the VBScript should pass a variable that will be populated with the output.
However in the PHP example you are just passing the string 'out' which isn't equivalent to what is being done in the VBScript.
Instead try passing a PHP variable to the method and then echoing that variable to screen, like this;
$result = $obj->GetDeviceStatus('', $out);
if ($result)
echo $out."<br />";
After a bit of digging it appears according to the PHP Reference that you need to pass By Reference variables to COM using the VARIANT data type.
Quote from ferozzahid [at] usa [dot] com on PHP - COM Functions
"To pass a parameter by reference to a COM function, you need to pass VARIANT to it. Common data types like integers and strings will not work for it."
With this in mind maybe this will work;
$out = new VARIANT;
$result = $obj->GetDeviceStatus('', $out);
if ($result)
echo $out."<br />";

How to do mysql_data_seek in CodeIgniter?

I'm trying to reset the pointer to the first record in CodeIgniter. Consider the following greatly simplified code:
$query_milestones = "SELECT * FROM milestones";
$milestones = $this->db->query($query_milestones);
foreach($milestones->result() as $milestoneRow){
// do something
}
$milestones->data_seek(0); // <--- This gives me Fatal error.
foreach($milestones->result() as $milestoneRow){
// do something else
}
This gives me:
Fatal error: Call to undefined method CI_DB_mysql_result::data_seek()
How can I do a mysql_data_seek with CodeIgniter?
UPDATE: It seems VERY odd to me but resetting the pointer apparently is not necessary. The following does what I want but not what I expect:
$query_milestones = "SELECT * FROM milestones";
$milestones = $this->db->query($query_milestones);
foreach($milestones->result() as $milestoneRow){
// do something
}
// As soon as the foreach is reached, the first record is retrieved again.
foreach($milestones->result() as $milestoneRow){
// do something else
}
try #$this->db->data_seek(0); instead of $milestones->data_seek(0);
You can try $milestones->_data_seek(0); but I have not used CodeIgniter in a while and supposedly it is a private method, at least it used to be.

Problem in implementing Sphinx API along with Cake php

I am working on project where I need to implement SphinxSearch with Cake php. So I am simply trying to use a component and behaviour into it. The link to it, is :-
http://bakery.cakephp.org/articles/eugenioclrc/2010/07/10/sphinx-component-and-behavior
I am requesting Sphinx API like below :
$sphinx = array('matchMode' => SPH_MATCH_ALL, 'sortMode' => array(SPH_SORT_EXTENDED => '#relevance DESC'));
$results = $this->ModelName->find('all', array('search' => 'Search_Query', 'sphinx' => $sphinx));
pr($result);
For above it is working fine ,but when I tried to minimise the response time querying to a particular field of the table (using extended match modes,i.e. SPH_MATCH_EXTENDED2) , Sphinx just fails to output any result. The extended query which I used is given below :-
$sphinx = array('matchMode' => SPH_MATCH_EXTENDED2, 'sortMode' => array(SPH_SORT_EXTENDED => '#relevance DESC'));
$results = $this->ModelName->find('all', array('search' => '#Field_name Search_Query', 'sphinx' => $sphinx));
pr($results);
Can anyone recognise where am I going wrong with it? Please help if I am going wrong some where.
Thanks in advance.
Btw, when you use EXTENDED2 mode make sure your rank mode is set accordingly.
Edit:
Anyway back to you problem, looking at that component/behavior code you can see right away that no error checking is done whatsoever. Try changing the code a bit so you can at least see the errors and/or warnings.
Component
if(!isset($query['search'])){
$result = self::$sphinx->Query('', $indexes);
} else {
$result = self::$sphinx->Query($query['search'], $indexes);
}
if ($result === false) {
// throw new SphinxException();
die(self::$sphinx->GetLastError());
}
$warn = self::$sphinx->GetLastWarning();
if ($warn) echo $warn;
Behavior
$result=$this->runtime[$model->alias]['sphinx']->search($s);
if ($result === false) {
die($this->runtime[$model->alias]['sphinx']->GetLastError());
}
$warn = $this->runtime[$model->alias]['sphinx']->GetLastWarning();
if ($warn) echo $warn;
I hope that helps.
As you said ,
Sphinx just fails to output any result.
That means it's an error :
Please check whether you have added the specific field to the indexing by using sql_query
Also check if the field you are searching for is not an attribute
As per the sphinx documentation :
Attributes, unlike the fields, are not full-text indexed. They are stored in the index, but it is not possible to search them as full-text, and attempting to do so results in an error.

Categories