Data not showing from my mysql server - php

So i'm trying pull data from my MySQL server here's my php code it want show none of the data i need help
<?php
$action = $_GET['action'];
$id = $_GET['id'];
$myID = $_GET['memberID'];
// Load Servers
$loadServers = $db->fetchAll("SELECT * FROM servers WHERE id = ? AND memberID = ?", array($id, $myID));
if($loadServers) {
foreach($loadServers as $loadServer) {
$id = $loadServer['id'];
$serverName = $loadServer['serverName'];
$serverType = $loadServer['serverType'];
$OS = $loadServer['OS'];
$hostName = $loadServer['hostName'];
$serverNode = $loadServer['serverNode'];
$IP = $loadServer['IP'];
}
}
?>
i don't know what i'm doing wrong can somebody help me.

So when i was grabbing the data from the MySQL server i had add on to the link i had set this how my link look like
Link Before
listserver.php?serverID=<?php echo $serverID;?>
Link Now
listserver.php?serverID=<?php echo $serverID;?>&memberID=<?php echo $memberID;?>
thank guys for the help i had to really look at my code in fix it

Related

Payment with ePay PHP API

In the last one week and a half, I've been looking for an answer on the question: how do I get my payment API to work?
I have a test account with the Danish payment gateway provider ePay/Bambora.
I have no problem getting the JavaScript version to Work, but I'd like to do the payment by an PHP-api, to make sure I have full control on which information is hidden for people who don't need to see it, information such as my "MerchantID".
ePay/Bambora seems to be very scarce with their information on how to fulfill a payment by PHP, or else I might be blind (or can't see the forest before the trees).
This is the code I've been written:
<?php
$epay_params['merchantnumber'] = "1234567"; //fake ID
$epay_params['transactionid'] = "-1";
$epay_params['amount'] = "9995";
$epay_params['group'] = "-1";
$epay_params['paymentcollection'] = "1";
$epay_params['orderid'] = "-1";
$epay_params['pbsResponse'] = "-1";
$epay_params['epayresponse'] = "-1";
$client = new SoapClient('https://ssl.ditonlinebetalingssystem.dk/remote/payment.asmx?WSDL');
$result = $client->capture($epay_params);
if($result->captureResult == true){
echo "Result OK"; //Capture OK
}
else{
echo json_encode( $result );
}
?>
This gives the following result: {"captureResult":false,"pbsResponse":-1,"epayresponse":-1008}
According to ePay/Bambora does -1008 mean, that the transactionid isn't found.
This seems to be correct, since there is no transaction called -1. I want to create a NEW payment, so I don't have a transaction id yet.
So either I have to create a transactionid on ePay/Bamboras server BEFORE I run the payment (how?) or I should not use the method "capture", but which method should I use then?
To be clear: I am not making a webshop, but just a payment system on my new calendar webapp.
The Question is: How do I fulfill a single payment via ePay/Bambora in PHP?
Try this http_build_query() for make URL perfectly
<?php
$url = 'https://ssl.ditonlinebetalingssystem.dk/remote/payment.asmx';
$params = array('WSDL');
$url .= '?' . http_build_query($params);
$epay_params['merchantnumber'] = "1234567"; //fake ID
$epay_params['transactionid'] = "-1";
$epay_params['amount'] = "9995";
$epay_params['group'] = "-1";
$epay_params['paymentcollection'] = "1";
$epay_params['orderid'] = "-1";
$epay_params['pbsResponse'] = "-1";
$epay_params['epayresponse'] = "-1";
$client = new SoapClient($url);
$result = $client->capture($epay_params);
if($result->captureResult == true){
echo "Result OK"; //Capture OK
}
else{
echo json_encode( $result );
}
?>
Hope this work either knock me

Create list of records and insert them later PHP MYSQL

I need to control who and when entered each subpage, and insert this information into MySQL. I have MYSQL table which will get the information(userid,subpage,subpageid, datetime).
function logstore(){
global $DB, $USER, $CFG;
$protocol = strpos(strtolower($_SERVER['SERVER_PROTOCOL']),'https')
=== FALSE ? 'http' : 'https';
$host = $_SERVER['HTTP_HOST'];
$script = $_SERVER['SCRIPT_NAME'];
$currentUrl = $protocol . '://' . $host . $script;
$newsurl = $CFG->wwwroot.'/news/view.php';
$produrl = $CFG->wwwroot.'/prod/view.php';
$materialurl = $CFG->wwwroot.'/material/index.php';
$datetime = date_create()->format('Y-m-d H:i:s');
$records = new stdClass();
$records->userid = $USER->id;
if($currentUrl == $newsurl){
$records->activity = 'news';
$records->activityid = $_GET['id'];
}elseif ($currentUrl == $produrl){
$records->activity = 'prod';
$records->activityid = $_GET['id'];
}
elseif ($currentUrl == $materialurl){
$records->activity = 'material';
$records->activityid = $_GET['id'];
}
$records->datetime = $datetime;
$DB->insert_record('logstore', $records);}
Im calling this function on top of /news/view.php, /prod/view.php, /material/index.php.
Its working fine, but i need to optimize it a little. Is there any way i can insert those records when DB is free, or create list and insert them each hour?
//edit
I tried INSERT DELAYED but its not working with my DB :(
There is no standard way in Moodle/PHP to delay queries till the DB is free. "INSERT DELAY" is depracated in latest MySQL as you can see here : https://dev.mysql.com/doc/refman/5.7/en/insert-delayed.html
I can suggest two options:
Check your DB performance using http://mysqltuner.pl - maybe more memory/cache can help in performance.
Use another server for this log - so the load will be distributed on more servers.

Writing .php file using php code

Hi there I'm trying to write a .php file using this code, server replying this error : syntax error, unexpected '0' (T_LNUMBER) in
I wanna know how can I write integer in php file as you can see
$status1 = \''0'\';
This code having problem, anybody please tell me what to do.
<?php
if(isset($_POST['user1'])){
$data = urldecode('%3C').'?php
$user1 = \''.$_POST['user1'].'\';
$pass1 = \''.$_POST['pass1'].'\';
$status1 = \''0'\';
$user2 = \''.$_POST['user2'].'\';
$pass2 = \''.$_POST['pass2'].'\';
$status2 = \''0'\';
$user3 = \''.$_POST['user3'].'\';
$pass3 = \''.$_POST['pass3'].'\';
$status3 = \''0'\';
$user4 = \''.$_POST['user4'].'\';
$pass4 = \''.$_POST['pass4'].'\';
$status4 = \''0'\';
$user5 = \''.$_POST['user5'].'\';
$pass5 = \''.$_POST['pass5'].'\';
$status5 = \''0'\';
$user6 = \''.$_POST['user6'].'\';
$pass6 = \''.$_POST['pass6'].'\';
$status6 = \''0'\';
$user7 = \''.$_POST['user7'].'\';
$pass7 = \''.$_POST['pass7'].'\';
$status7 = \''0'\';
$user8 = \''.$_POST['user8'].'\';
$pass8 = \''.$_POST['pass8'].'\';
$status8 = \''0'\';
$user9 = \''.$_POST['user9'].'\';
$pass9 = \''.$_POST['pass9'].'\';
$status9 = \''0'\';
$user10 = \''.$_POST['user10'].'\';
$pass10 = \''.$_POST['pass10'].'\';
$status10 = \''0'\';
?'.urldecode('%3E');
$fx=fopen('datauser.php','w');
fwrite($fx,$data);
fclose($fx);
if($fx === false) {
header("Location: ./tokensettings.php?save=err");
}
else {
header("Location: ./tokensettings.php?save=success");
}
}
?>
Thank you so much.
Here is how my form looks like.
If you still want to do it your way you need to use the \ correctly for each ' to be included in the string even those in [ ] - not saying the final string produced would actually work but it is based on your code and my best guess at your desired result
<?php
$string1=' \'\'.$_POST[\'user1\']\'\';';
$string1=$string1.'\'\'0\'\';';
echo $string1;
?>
The whole urlencoding stuff is not needed at all, your quoting and escaping is messy and incorrect. and why not simply use file_put_contents? Use HEREDOC to avoid messy escaping.
file_put_contents('datauser.php', <<<CONTENT
<?php
\$user = '{$_POST['user']}';
\$pass = '{$_POST['pass']}';
\$status = '0';
CONTENT
);
but if you really want to use files as data storage, I would encourage you to save it in a data format like xml or json instead of writing php.
// save data to file ($_POST used as example...)
file_put_contents('user.json', json_encode($_POST));
// read data
$data = json_decode(file_get_contents('user.json'));

PHP code in string

I was amazed I didn't found answer on Google for this answer.
So basically I have a PHP code which have to be stored in a variable as a string. Unfortunately PHP recognize the opening and ending tag not as a string but a PHP code... I want it as a string :)
$settings_string =
'
<?php
//Locker ID
$userToSearch = '.$_POST["usertosearch"].';
//User Folder
$userFolder = '.$folder.';
//User Link
$userLink = '.$_POST["userlink"].';
// Username and pass
$affiliateuser = '.$_POST["affiliateuser"].';
$affiliatepassword = '.$_POST["affiliatepassword"].';
?>
';
you can use like this.
if u tell your purpose. so i can give you better than this.
$settings_string ='
<?php
//Locker ID
$userToSearch = \'.$_POST["usertosearch"].\';
//User Folder
$userFolder = \'.$folder.\';
//User Link
$userLink = \'.$_POST["userlink"].\';
// Username and pass
$affiliateuser = \'.$_POST["affiliateuser"].\';
$affiliatepassword = \'.$_POST["affiliatepassword"].\';
?>
';
Now you have to use like this
$file = fopen('file_name.php', 'w');
fwrite($file, $settings_string);
If you want the value of the $_POST injected in there you still need to quote it properly in the output.
$settings_string =
'
<?php
//Locker ID
$userToSearch = "'.$_POST["usertosearch"].'"; //add them quotes!!!!
//User Folder
$userFolder = "'.$folder.'";
//User Link
$userLink = "'.$_POST["userlink"].'";
// Username and pass
$affiliateuser = "'.$_POST["affiliateuser"].'";
$affiliatepassword = "'.$_POST["affiliatepassword"].'";
?>
';
I'll assume $_POST["usertosearch"] = 'user' currently in your output would be this.
$userToSearch = user;
When instead you want
$userToSearch = "user";
Above you will see the added double quote, to properly quote the strings in the output file. That file still has to have valid syntax.
As a note, if any of the post values contain " your gonna have issues, unless you do addslashes() for them.
For example
$userLink = "'.$_POST["userlink"].'";
Assume this is $_POST["userlink"] = 'link' OR
$userLink = "link";
See the issue with that. When you'll want this
$userLink = "link";
Your looking for eval
<?php
$settings_string ='
//Locker ID
$userToSearch = '.$_POST["usertosearch"].';
//User Folder
$userFolder = '.$folder.';
//User Link
$userLink = '.$_POST["userlink"].';
// Username and pass
$affiliateuser = '.$_POST["affiliateuser"].';
$affiliatepassword = '.$_POST["affiliatepassword"].';
';
eval($settings_string);

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.

Categories