zend framework Creating default object from empty value - php

im trying to modify a code, when i submit the form im getting this error "Creating default object from empty value". I make n echo statment in $request->isPost is not echoing. this my code below
public function addAction() {
$report = new Report();
$request = $this->getRequest ();
$validateOnly = $request->isXmlHttpRequest ();
if ($validateOnly)
$this->setNoRenderer ();
$userObj = new User ( );
$userRow = $userObj->createRow();
$status = ValidationContainer::instance ();
$userArray = $userRow->toArray ();
$userArray['acls'] = User::getACLs ( $user_id ); //set acls
$this->viewAssignEscaped ( 'user', $userArray );
$locations = Location::getAll();
$this->viewAssignEscaped('locations', $locations);
//var_dump($locations); exit;
if ($request->isPost()) {
self::fillFromArray ( $userRow, $details );
$userRow->is_blocked = 0;
if ($id = $userRow->save ()) {
in the provider_code table.
$this->insertPlainPassword($this->getSanParam('password'), $id);
$status->setStatusMessage ( 'The new user was created.' );
$this->saveAclCheckboxes ( $id );
} else {
$status->setStatusMessage ( 'The user could not be saved.' );
}
}
}
}
i have been trying to resolve it for weeks now.
}

Related

WordPress passing vairiable from shortcode into another function

I am trying to access php variable from wordpress shortcode function and use into og filter.
I have tried with php superglobals, set transient also, but nothing give the needed result.
Can someone take a look and help, thanks!
That's my code:
add_shortcode('test', 'get_sheet_value_shortcode');
function get_sheet_value_shortcode() {
ob_start();
$API = get_option('google_sheet_api');
$google_spreadsheet_ID = get_option('google_sheet_id');
$LANG = get_language_shortcode();
$api_key = esc_attr( $API);
$get_cell = new WP_Http();
$cell_url = "https://sheets.googleapis.com/v4/spreadsheets/$google_spreadsheet_ID/values/$LANG!A1:Z1000/?majorDimension=ROWS&key=$api_key";
$cell_response = $get_cell -> get( $cell_url);
if ( empty( $cell_response) ) {
return;
}
$json_body = json_decode($cell_response['body'],true);
$values = $json_body['values'];
//$values = json_encode($values);
array_shift($values); // removes first column key
if (! empty($values) ) {
$count = count($values);
// this will be using for share f-nality, so we can get same quote
$quote_number = array_search($rand_values, $values);
$rand_values = $values[array_rand($values)];
$image = (! empty($rand_values[3]) ) ? $rand_values[3] : '';
$GLOBALS['ogimage'] = $image;
}
ob_get_clean();
}
add_filter( 'aioseo_facebook_tags2', 'aioseo_filter_facebook_title2', 99 );
function aioseo_filter_facebook_title2( $facebookMeta ) {
$image = $GLOBALS['ogimage'];
if ( is_page('test') ) {
$facebookMeta['og:image'] = $image;
}
return $facebookMeta;
}

updating mysql json array using php

as the title says, I made a PHP method to update a JSON object from MySQL using a defined key-value and new-value basically the function fetches the JSON column from the database and then looping throw each object in the array and compare it to the item and if the key-value matches the item the key-value
will be replaced with the new value. as I think the problem is in the newArray because the function inserts the same old array without any changes!
<?
public function AlterJSON($billingID,$item,$key,$newValue){
if($this->connected === true){
try{
$ColumnJ = $this->connection->prepare("SELECT `items` FROM `bills` WHERE id=:id");
$ColumnJ->bindParam(":id",$billingID);
$ColumnJ->execute();
$fetched = $ColumnJ->fetchColumn();
$decoded = json_decode($fetched);
foreach($decoded as $product){
if($product->$key == $item){
$product->$key = $newValue;
$newArray = json_encode($decoded);
$alterSQL = $this->connection->prepare('UPDATE `bills` SET items=:newArray WHERE id=:id');
$alterSQL->bindParam(':newArray',$newArray);
$alterSQL->bindParam(':id',$billingID);
$alterSQL->execute();
}
}
}
catch(PDOException $e){
if($this->errors === true){
return $this->error($e->getMessage());
}else{
return false;
}
}
}
}
?>
method call($productqty and $productPrice are the key-value getting from json)
<?php
require("Core.php");
// Calling DbConnect Object //
$dbConnection = new dbConnect('127.0.0.1','root','0928065698ko','project-db');
// Billing $_PSOT //
$ProductQty = $_POST['qty-input'];
$ProductPrice = $_POST['price-input'];
$BillingTotal = $_POST['total-input'];
$BillID = $_POST['Billid'];
// Billing Requset //
if(isset($ProductPrice) && isset($ProductQty) && isset($BillingTotal)){
$dbConnection->AlterJSON($BillID,$ProductPrice,'price',$ProductPrice);
}
?>
I can't be sure if the following is correct as I have no way currently to test the JSON datatype within mysql nor a suitable table with json data so it might be riddled with mistooks.
<?php
/*
It is better to test that these POST variables are set than try to assign
as variables later not knowing if they are or are not set. `isset` will
accept multiple arguments.
*/
if( isset(
$_POST['qty-input'],
$_POST['price-input'],
$_POST['total-input'],
$_POST['Billid']
) ){
# no need to include this if the variables are not set
require('Core.php');
$dbConnection = new dbConnect('127.0.0.1','root','0928065698ko','project-db');
$ProductQty = $_POST['qty-input']; # this does not get used
$ProductPrice = $_POST['price-input'];
$BillingTotal = $_POST['total-input']; # this does not get used
$BillID = $_POST['Billid'];
$dbConnection->AlterJSON( $BillID, $ProductPrice, 'price', $ProductPrice );
}
?>
<?php
/* previous methods */
public function AlterJSON( $bid=false, $item=false, $key=false, $value=false ){
try{
if( $bid && $item && $key && $value && $this->connected === true ){
$stmt=$this->connection->prepare('select `items` from `bills` where `id`=:id');
$stmt->execute( [ ':id' => $bid ] );
$fetched = $stmt->fetchColumn();
$decoded = json_decode( $fetched );
$stmt=$this->connection->prepare('update `bills` set `items`=:json where id=:id');
foreach( $decoded as $index => $product ){
if( $product->$key == $item ){
$decoded[ $index ]->$key = $value;
$json = json_encode( $decoded );
$stmt->execute([
':json' => $json,
':id' => $bid
]);
}
}
return true;
}
return false;
} catch( PDOException $e ){
return $this->errors === true ? $this->error( $e->getMessage() ) : false;
}
}
/* more methods */
?>

Trying to get property of non-object error in PHP

I'm trying to save my data using php. This is how I tried:
<?php
session_start();
if(!isset($_SESSION["MemberID"])) header("Location:logout.php");
include '../config.php';
include '../momdb.php';
$page_title = "Customers";
$mode = "Save";
$db = 'db';
$showmessage = false;
$message = "";
if (isset ( $_POST ["btnSave"] )) {
$data = new table ();
$data->MomID = $_POST ["CustomerID"];
$data->CustomerName = $_POST ["CustomerName"];
$data->FromDate = string_to_date ( $_POST ["FromDate"] );
$data->ToDate = string_to_date ( $_POST ["ToDate"] );
$data->CreatedBy = $_SESSION["MemberID"];
$data->CreatedDatetime = date ( "Y-m-d H:i:s" );
$data->LastModifiedBy = $_SESSION["MemberID"];;
$data->LastModifiedDatetime = date ( "Y-m-d H:i:s" );
$rows = array ();
if (intval ( $data->CustomerID) > 0) {
$rows = $db::Update ( $data );
} else {
$rows = $db::Save ( $data );
}
if (intval ( $rows ["WebID"] ) > 0) {
$date = new DateTime ();
header ( "Location: customerlist.php?msg=yes&msgt=s&t=" . $date->getTimestamp () . "&mtext=Record saved successfully" );
} else {
$showmessage = true;
$message = $rows ["Message"];
}
} elseif (isset ( $_GET ["CustomerID"] )) {
$data = $db::GetByID ( $_GET ["CustomerID"] );
if ($data == false) {
$data = new table ();
$data->CustomerID = 0;
}
}
if ($data->CustomerID == "0")
$mode = "Save";
else
$mode = "Update";
?>
This code is for sending my values to the db page for saving them in the DB. I've used the PDO method. This is the first time I'm saving the record this way. That's why there is lots of confusion. The following code shows the Save() method, which I used to save the values to the DB.
public function Save(table $customer) {
$data = new DB ();
$stmt = $data->connection->prepare ( "CALL proc_CreateCustomer (:CustomerName, :FromDate,:ToDate,:CreatedBy, :CreatedDatetime, :LastModifiedBy, :LastModifiedDatetime)" );
$stmt->bindParam ( ':CustomerName', trim ($customer->CustomerName ));
$stmt->bindParam ( ':FromDate', $customer->FromDate );
$stmt->bindParam ( ':ToDate', $customer->ToDate);
$stmt->bindParam ( ':CreatedBy',$customer->CreatedBy );
$stmt->bindParam ( ':CreatedDatetime', $customer->CreatedDatetime );
$stmt->bindParam ( ':LastModifiedBy',$customer->LastModifiedBy );
$stmt->bindParam ( ':LastModifiedDatetime', $customer->LastModifiedDatetime );
$stmt->execute ();
$record = $stmt->fetch ( PDO::FETCH_OBJ );
if ($record == false) {
return array (
"WebID" => 0,
"Message" => $record->Message,
"AppID" => $customer->AndroidID
);
} else {
return array (
"WebID" => $record->CustomerID,
"Message" => $record->Message,
"AppID" => $customer->AndroidID
);
}
}
This is how I've tried. But, whenever I try to save the details, it shows: " Trying to get property of non-object in D:\Workspace\Application\momdb.php on line 39", ie it shows error in the line "Message" => $record->Message,"AppID" => $customer->AndroidID. I don't what's wrong with this. Can someone tell me what should I change so that it work fine?
if ($record == false) {
return array (
"WebID" => 0,
"Message" => $record->Message,
"AppID" => $customer->AndroidID
);
}
In this piece of code $record is false(y), so $record->Message doesn't exist.

PHP error fetching json file

Can someone help why my JSON file can't show? I beginner for JSON. This is my code, its only show blank document. I am learning this tutorial from this website http://contohprogramandroid.blogspot.com/2013/10/contoh-program-android-aplikasi-wisata.html. thank you so much.
this my image when running the code.
//this is the code webservice.php
<?php
class Database {
private $host = "localhost";
private $user = "root";
private $pass = "";
private $db = "wisata_jogja";
private $conn;
// constructor
function __construct() {
try{
$this->conn = new PDO( "mysql:host=".$this->host.";dbname=".$this->db, $this->user, $this->pass );
}catch( PDOException $e ) {
echo "error pdo $e";
}
}
public function showAllData( $table ) {
$sql ="SELECT * FROM $table";
$q = $this->conn->query( $sql ) or die( "Failed !!" );
while ( $r = $q->fetch( PDO::FETCH_ASSOC ) ) {
$data[] = $r;
}
return $data;
}
}
$database = new Database();
$response = array();
if ( isset( $_GET['get'] ) && $_GET['get']=='lokasi' ) {
$response['location'] = array();
foreach ( $database->showAllData( 'lokasi' ) as $value ) {
$kode = array();
extract( $value );
$kode['id'] = $id;
$kode['nama'] = $nama;
$kode['alamat'] = $alamat;
$kode['gambar'] = $gambar;
$kode['lat'] = $lat;
$kode['lng'] = $lng;
array_push( $response['location'], $kode );
}
echo json_encode( $response );
}
?>
Your condition to output is this:
if ( isset( $_GET['get'] ) && $_GET['get']=='lokasi' ) {
Thus, the script won't output any JSON since condition is not met.
From your screenshot it is clear your are missing the GET parameters.
In your browser add the parameter to the url:
http://localhost/wisata/webservice.php?get=lokasi
It's always good to take alternative action when condition is not true.
You should always echo something just so you know what is going on:
if ( isset( $_GET['get'] ) && $_GET['get']=='lokasi' ) {
//..............
echo json_encode( $response );
}else{
echo "cannot output JSON data: parameter is missing!!;
}
Are you sure that you pass the GET variable "lokasi" to your script ?
Otherwise, it would not go through the if condition
if(isset($_GET['get'] ) && $_GET['get']=='lokasi')
You can check this by trying to dump the variable or any foobar data inside the if condition to verify your code goes that far, for instance :
if(isset($_GET['get'] ) && $_GET['get']=='lokasi') {
$response['location'] = array();
$myTest = array('test');
var_dump($myTest); // Should display something on screen
// The rest of your code here

why sometime can get error 404 not found (soapclient- response has contents of the response), how to solve

i have a NUSOAP webservice
when i run from client it visbile the error
wsdl error: Getting http://carvilshoe.cz.cc/index.wsdl.php?wsdl - HTTP ERROR: Unsupported HTTP response status 404 Not Found (soapclient->response has contents of the response)
below is my code at client
i have to client (mitra)
mitra = http://pakalolosepatu.cu.cc/
mitra1 = http://carvilshoe.cz.cc/
--
//wsdl configuration
$wsdl = mitra . 'index.wsdl.php?wsdl';
$ws_client_pakalolo = new nusoap_client ( $wsdl, true );
$wsdl = mitra1 . 'index.wsdl.php?wsdl';
$ws_client_sepatubermerek = new nusoap_client ( $wsdl, true );
//debug if needed
//$ws_client->debugLevel = 1;
//header configuration
$user = "+++";
$pass = "+++";
//encrypt header value
$user = base64_encode ( $user );
$pass = base64_encode ( $pass );
$header = '<AuthSoapHeader>
<UserName>' . $user . '</UserName>
<Password>' . $pass . '</Password>
</AuthSoapHeader>';
//set header
$ws_client_pakalolo->setHeaders ( $header );
$ws_client_sepatubermerek->setHeaders ( $header );
// Function to print Fault
function detect_fault() {
global $ws_client_pakalolo;
//detect fault and error
if ($ws_client_pakalolo->fault) {
exit ( $ws_client_pakalolo->faultstring );
} else {
$err = $ws_client_pakalolo->getError ();
if ($err) {
exit ( $err );
}
}
}
function detect_fault_mitra2() {
global $ws_client_sepatubermerek;
//detect fault and error
if ($ws_client_sepatubermerek->fault) {
exit ( $ws_client_sepatubermerek->faultstring );
} else {
$err = $ws_client_sepatubermerek->getError ();
if ($err) {
exit ( $err );
}
}
}
function call_list_barang($limit, $offset, $order_by, $where) {
global $ws_client_pakalolo,$ws_client_sepatubermerek;
//parameters configuration
$params = array ('limit' => $limit, 'offset' => $offset, 'order_by' => $order_by, 'where' => $where);
//call method service
$ws_data = $ws_client_pakalolo->call ( 'data_barang', $params);
detect_fault ();
//decode data
$ws_data = unserialize ( base64_decode ( $ws_data ) );
//call method service
$ws_data1 = $ws_client_sepatubermerek->call ( 'data_barang', $params);
detect_fault_mitra2 ();
//decode data
$ws_data1 = unserialize ( base64_decode ( $ws_data1 ) );
$data_paka = $ws_data['data'];
$data_se = $ws_data1['data'];
$data = array_merge($data_paka,$data_se);
return $data;
}
function call_list_stock($mitra,$no_barang) {
global $ws_client_sepatubermerek, $ws_client_pakalolo;
//parameters configuration
$params = array ('no_barang' => $no_barang );
if($mitra == "Pakalolo"){
//call method service
$ws_data = $ws_client_pakalolo->call ( 'list_stock', $params);
detect_fault ();
//decode data
}else{
//call method service
$ws_data = $ws_client_sepatubermerek->call ( 'list_stock', $params);
detect_fault_mitra2 ();
//decode data
}
$ws_data = unserialize ( base64_decode ( $ws_data ) );
return $ws_data;
}
?>
why can happen this error and how to solve,
can someone help??
thanks
Try to set forced endpoint
$client = new nusoap_client('http://LOCATION_TO_WSDL','wsdl');
$client -> setEndpoint('http://LOCATION_OF_ENDPOINT');
The endpoint is a connection point where HTML files or active server pages are exposed.

Categories