Filemaker via PHP - php

I am working on a php script that gets the values of the fields inside a Filemaker database. What I want to accomplish now is how do I edit/update the field values of each field to new values and should be saved in the Filemaker database. This is my code in getting the field:
require_once ('../../FileMaker.php');
$fm = new FileMaker('dataStest.fp7', 'https://secure.smartdecision.org', 'web', 'webtest');
$findCommand = $fm->newFindCommand('List');
$findCommand->addFindCriterion('ID1',$ftype);
$result = $findCommand->execute();
$records = $result->getRecords();
foreach ($records as $record) {
if ($record->getField('ID3') == "ACTIVE" && $record->getField('ftyCat') == "treatment") {
echo $record->getField('d15'). '<br>';
}
If(FileMaker::isError($result)){
echo "Could not connect to the field";
}
Any suggestions would be very helpful. Thank you!

You just need to use the setField method as documented in the FileMaker PHP API (here's the page for the documentation on the FileMaker_Record class) and then commit your record with commit:
...
$record->setField('d15', 'new value');
$record->commit();
...

Related

Balance transferring transaction - PHP and MySQL

I'm in a middle of a project and I need to create a page in which the user account will be able to transfer a certain amount of "money" to another registered account.
After the transfer action ends, I need to have a transcript of the transaction.
I created a new DB that contains all the transactions but I can't figure out how to call the data.
I tried to use this in the api.php:
`//get all transactions
case "get_all_transactions":
$cursor = $MySQLdb->prepare("SELECT * FROM transactions");
$cursor->execute();
$retval = "";
foreach($cursor->fetchAll() as $row){
if ($row["send_account"] == $user OR $row["recive_account"] == $user){
$retval = retval . "<br>"echo .$row['send_account']."<br>".$row['recive_account']."<br>".$row['amount'];
}else{
$msg = "nope";
}
}
echo '{"success":"true","data":"'.$retval.'"}';
die();
break;`
I add this in the transaction.php page:
//get all transactions
$.post("api.php",{"action":"get_all_transactions"},function(data){
if(data.success == "true"){
$("#transactions_history").html(data.data);
}
});
I can't figure out how to continue.
Can anyone assist, please?
If you have any other way, it will be great.
Thanks!

Form Post Data As Array Value

I'm trying to integrate an API builder to my control panel through a form or post data. I can't figure out how to put the post data as the value for the array.
I tried using print_r($_POST['VALUE']) with and without quotes.
I tried using just $_POST['VALUE'] with and without quotes.
I also tried to set $value = $_POST['VALUE'] then using $value with and without quotes but that caused an error 500.
Here is the code I am trying to use:
$res = $api->remoteCall('requestLogin', array(
'type' => 'external',
'domain' => 'print_r($_POST['domain'])',
'lang' => 'en',
'username' => 'print_r($_POST['uname'])',
'password' => 'print_r($_POST['pass'])',
'apiUrl' => '127.0.0.1',
'uploadDir' => '/web/'.print_r($_POST['domain']).'/public_html',
I apologize as I am new to PHP, but thank you in advance.
I'm not sure what other logic is being done there, how the post variables are being sent to the script your sample code is running on, or any of the other details which might point towards a more complete solution but here are some basic tips to help you troubleshoot.
The post variables should be formatted like this:
$res = $api->remoteCall('requestLogin', array(
'domain' => $_POST['domain'],
You can dump the entire post array to the screen by doing
print_r($_POST);
This should output your array to the screen so you can verify that you're receiving the post data in the code and should help you fix any typos or misnamed post variables. If the array has the key as $_POST['domainName'] and you're echoing $_POST['domain']
You're calling code (the "form or post data") should have the post fields in place and named correctly in order for them to be sent to the script
<input type="text" name="domain">
You should be performing some basic validation on your post fields before adding them to something that's going to be stored anywhere or sent off to a third-party. At the most minimal you'll want to check that there is a value being set for the essential fields (required fields) and I'd look to make sure the values are matching requirements of the API you're passing them off to.
Several things may go wrong when using api. POST values, input values, API call or connection or maybe api response. So not only at the time of implementation and coding but also when integrating api call script with the application there should be some sort of testing and error handling in place. A simple script can be like this
$error = array();
$request = array();
$request['type'] = 'external';
if (isset($_POST['domain']) && !empty($_POST['domain'])) {
$request['domain'] = $_POST['domain'];
$request['uploadDir'] = "/web/{$_POST['domain']}/public_html";
} else {
$error[] = "Domain is empty";
}
if (isset($_POST['uname']) && !empty($_POST['uname'])) {
$request['username'] = $_POST['uname'];
} else {
$error[] = "Username is empty";
}
if (isset($_POST['pass']) && !empty($_POST['pass'])) {
$request['password'] = $_POST['pass'];
} else {
$error[] = "Username is empty";
}
$request['lang'] = 'en';
$request['apiUrl'] = '127.0.0.1';
if (count($error) > 0) {
echo implode( "<br>" , $error );
} else {
try{
$res = $api->remoteCall('requestLogin',$request);
} catch ( Exception $e ) {
print_r($e);
exit();
}
}

Creating a Custom PHP bot

I am trying to create a bot to automatically scrape some data from a website. I am trying to use the Snoopy PHP class for this.
The problem I am having is that I cannot submit the login form page. I am passing the username and password in the field, but "nothing happens" - I don't get logged in and an error is not returned (such as invalid password).
I have tried using cURL directly (without the Snoopy class), but that doesn't help.
I feel that I am not passing the form variables correctly. I would appreciate it if someone could point me in the right direction.
The code I am using is:
$snoopy = new Snoopy;
$submit_url = "";
$submit_vars['ctl00$cphMainContent$ctl00$UsernameTextBox'] = "";
$submit_vars['ctl00$cphMainContent$ctl00$PasswordTextBox'] = "";
if($snoopy->submit($submit_url,$submit_vars)) {
while(list($key,$val) = each($snoopy->headers)) {
echo $key.": ".$val."<br>\n";
}
echo "<p>\n";
echo "<PRE>".htmlspecialchars($snoopy->results)."</PRE>\n";
} else {
echo "error fetching document: ".$snoopy->error."\n";
}

get json data in function php

I am new in this json chapter.I have a file named mysql_conn.php .This file have a php function to call data from mysql database.So can anyone help me to create one json file to get data from mysql_conn.php.Below is my code
mysql_conn.php
function getWrkNoTest($wrkno){
$conf = new BBAgentConf();
$log = new KLogger($conf->get_BBLogPath().$conf->get_BBDateLogFormat(), $conf->get_BBLogPriority() );
$connection = MySQLConnection();
$getWrkNoTest ="";
$lArrayIndex = 0;
$query = mysql_query("
SELECT
a.jobinfoid,
a.WRKNo,
a.cate,
a.det,
a.compclosed,
a.feedback,
a.infoID,
b.callerid,
b.customername
FROM bb_jmsjobinfo a
LEFT JOIN bb_customer b
ON a.customerid = b.customerid
WHERE a.WRKNo = '$wrkno';"
);
$result = mysql_query($query);
$log->LogDebug("Query[".$query."]");
while ($row = mysql_fetch_array($result)){
$getWrkNoTest = array("jobinfoid"=>$row['jobinfoid'],
"WRKNo"=>$row['WRKNo'],
"cate"=>$row['cate'],
"det"=>$row['det'],
"compclosed"=>$row['compclosed'],
"feedback"=>$row['feedback'],
"infoID"=>$row['customerid'],
"customerid"=>$row['infoID'],
"callerid"=>$row['callerid'],
"customername"=>$row['customername']);
$iList[$lArrayIndex] = $getWrkNoTest;
$lArrayIndex = $lArrayIndex + 1;
}
$QueryResult = print_r($getWrkNoTest,true);
$log->LogDebug("QueryResult[".$QueryResult."]");
closeDB($connection);
return $iList;
}
json.php
if ($_GET['action']=="getJsonjms"){
$wrkno = $_GET["wrkno"];
if($wrkno != ""){
$jms = getWrkNoTest($wrkno);
if(!empty($jms)){
echo json_encode($jms);
}else{
echo "No data.";
}
}else{
echo "Please insert wrkno";
}
}
I dont know how to solve this.Maybe use foreach or something else.Sorry for my bad english or bad explanation.I'm really new in this json things. Any help will appreciate.Thanks
If I understand your question right, you want to convert the results you receive from your MySQL query into JSON and then store that data into a file?
If this is correct, you can build off of what you currently have in json.php. In this block here, you use json_encode():
if(!empty($jms)){
echo json_encode($jms);
}
We can take this data and pass it to file_put_contents() to put it into a file:
if (!empty($jms)) {
$json = json_encode($jms);
// write the file
file_put_contents('results.json', $json);
}
If this is a script/page that's visited frequently, you'll want to make the filename (above as results.json) into something more dynamic, maybe based on the $wrkno or some other schema.

From PHP to Javascript

I have the following code on my PHP webapp, it uses PHP to look for products in a Sqlite3 Databse file locally. I was tryng to convert it into an Android App with Phonegap, but sadly Phonegap does't work with PHP, so I thought I could make a JavaScript file replacing the PHP.
However, I can't get it to work. In case what I am trying to do is impossible, I guess there should be a way to execute the PHP files on the server and just display the results on the app.
($_GET['busq']){
$busq=$_GET['busq'];
function ultlet($cadena) {
$cant = strlen($cadena);
$cant--;
$let = substr($cadena, $cant);
if ($let == "s") {
$cadena = substr($cadena, 0, $cant);
}
return $cadena;
}
str_replace("-",$busq," ");
$arreg=explode(" ",$busq);
$cuent=count($arreg);
for($a=0;$a<$cuent;$a++){
$arreg[$a] = ultlet($arreg[$a]);
}
$query="SELECT * from MyTable WHERE";
for($i=0;$i<$cuent;$i++){
if ($i>=1){
$query=$query." AND ";
}
$query=$query." (col1 LIKE \"%$arreg[$i]%\" OR col6 LIKE \"%$arreg[$i]%\") ";
}
$db = new PDO('sqlite:MyDatabase.sqlite');
$result = $db->query($query);
foreach ($result as $row) {
if ($row['codigo_cat']!=null){
$class = 'class="image"';
}else{
$class = 'class="row"';
}
echo '<div '.$class.' alt="'.$row['col4'].'">';
echo 'Codigo: '.$row['col2']." / ".$row['col3']."<br>";
echo 'Nombre: '.$row['col1']."<br>";
echo '</div>';
}
}
There is also another file wich based on the user's input on a search bar creates the variable 'busq' which is used to display the products and its prices.
Modify the PHP script to output its contents as an xml file, and use javascript's XMLHttpRequest function to create a request to the file, and get the information you need.

Categories