I got this error when i upload it to the FTP,
Strict Standards: Only variables should be passed by reference in /home/user/public_html/ref/hhhhh_hhhhh/index.php on line 15
Any idea what's wrong?
<?php
require_once 'jsonRPCClient.php';
$api_key = 'apikey';
$api_url = 'url';
$client = new jsonRPCClient($api_url);
$campaigns = $client->get_campaigns(
$api_key,
array (
# find by name literally
'name' => array ( 'EQUALS' => 'test' )
)
);
$CAMPAIGN_ID = array_pop(array_keys($campaigns));
if(isset($_POST['submit']))
{
$result = $client->add_contact(
$api_key,
array (
'campaign' => $CAMPAIGN_ID,
'name' => 'Test',
'email' => 'test#test.test',
)
);
$cid = "infod";
$site_url = $cid.".pokemon.com";
header("Location: http://$site_url") ;
}
?>
$result = $client->add_contact(
$api_key,
array (
'campaign' => $CAMPAIGN_ID,
'name' => 'Test',
'email' => 'test#test.test',
)
); /* <- missed the ";" */
Try changing
$CAMPAIGN_ID = array_pop(array_keys($campaigns));
to
$CAMPAIGN_ID = array_keys($campaigns);
$CAMPAIGN_ID = array_pop($CAMPAIGN_ID);
and see if it helps.
Related
I have been getting the error below when i try to enroll users to moodle through enrol_manual_enrol_users
Array ( [exception] => invalid_parameter_exception [errorcode] => invalidparameter [message] => Invalid parameter value detected [debuginfo] => enrolments => Invalid parameter value detected: Missing required key in single structure: roleid )
This is my code
$MoodleRest = new MoodleRest('http://localhost/moodle/webservice/rest/server.php', $this->token);
$enrolment = array(
"userid" => $user_id,
"courseid" => $course_id,
"roleid" => 4
);
$enrolments = array(array($enrolment));
$params = array( 'enrolments' => $enrolments );
$result_query = $MoodleRest->request('enrol_manual_enrol_users', $params);
if (!empty($result_query['exception'])) {
print_r(array('Error querying enroll', $result_query));
die();
}
$MoodleRest = new MoodleRest('http://40.81.1.212/moodle/webservice/rest/server.php', $this->token);
$par = array( //e_s_s
'enrolments' => array( //e_m_s
array( //e_s_s
'userid' =>$user_id ,
'courseid' =>$course_id , // PARAM_NUMBER VALUE_REQUIRED[]
'roleid' =>$role_id //PARAM_RAW VALUE_OPTIONAL [] ))
);
print_r($par);
echo "<br><br>";
$result_query = $MoodleRest->request('enrol_manual_enrol_users', $par);
if (!empty($result_query['exception'])) {
print_r(array('Error querying enroll', $result_query));
//die();
}
var_dump($result_query);
echo '</br>************************** Server Response EnrollUser()**************************</br></br>';
I have written below lines of code
$advsr_firstname="David"
$advsr_middlename ="";
// note that these two are passed through function parametre
$first_name=array('$or' => array(array("student.first_name" => new MongoRegex("/$advsr_firstname/i"))));
$last_name= array('$or' => array(array("student.last_name" => new MongoRegex("/$advsr_middlename/i"))));
$keyarguments = array(
'first_name=>advsr_firstname',
'last_name=>advsr_middlename'
);
$empty = "X9w+";
foreach ($keyarguments as $key => $value)
{
if(${$value} =='' || ${$value} =='0' || ${$value} =="Select")
{
${$key} = array('$or' => array(array("dummy_feild" => new MongoRegex("/$empty/i"))));
}
}
$orrollno= array('$or' => array(array("student.roll_no" => new MongoRegex("/$arg/i"))));
$query = array( '$or' => array($first_name,$last_name,$orrollno));
I am trying to write query dynamically so that $query will work properly.
I want that if "$advsr_middlename" is empty then the code should dynamically modify the expression $last_name in the loop like
$last_name = array('$or' => array(array("dummy_feild" => new MongoRegex("/$empty/i"))));
It is throwing error messages undefined variable first_name=>advsr_firstname
....
Please help me as the code is not working!!!
I think this could be the solution: fix the syntax of $keyarguments array from
$keyarguments = array(
'first_name=>advsr_firstname',
'last_name=>advsr_middlename'
);
to
$keyarguments = [
'first_name' => 'advsr_firstname',
'last_name' => 'advsr_middlename',
];
I am writing a web service in php using nusoap library. I can return simple variables such as string, integer and also only one complextype which is struct. But I can not return array of structs. I research nearly all example in a week about this but it doesn't work. So where I am going wrong?
Code
$server->wsdl->addComplexType('userSitesData','complexType','struct','all','',
array(
'id' => array('name'=>'id','type'=>'xsd:int'),
'siteName' => array('name'=>'siteName','type'=>'xsd:string'),
'workPlace' => array('name'=>'workPlace','type'=>'xsd:string'),
'situation' => array('name'=>'situation','type'=>'xsd:string')
)
);
// *************************************************************************
// Complex Array ++++++++++++++++++++++++++++++++++++++++++
$server->wsdl->addComplexType(
'userSiteDataList',
'complexType',
'array',
'',
'SOAP-ENC:Array',
array(),
array(
array(
'ref' => 'SOAP-ENC:arrayType',
'wsdl:arrayType' => 'tns:userSitesData[]'
)
),
'tns:userSiteDataList'
);
//Struct of above array
$server->wsdl->addComplexType(
'UserSiteList',
'complexType',
'struct',
'all',
'',
array(
'list' => array('name'=>'list','type'=>'tns:userSiteDataList')
)
);
// *************************************************************************
$server->register(
"userSitesList",
array('name' => 'xsd:int'),
array('return' => 'tns:UserSiteList'),
// namespace:
$namespace,
// soapaction: (use default)
false,
// style: rpc or document
'rpc',
// use: encoded or literal
'encoded',
// description: documentation for the method
'Use this service to list buildingsites belong given user.');
// *************************************************************************
//RETURN USER'S BUILDING SITES LIST
function userSitesList($id)
{
$list=array();
$conn=openConnection();
// Check connection
if ($conn->connect_error)
{
$error=("Connection failed: " . $conn->connect_error);
}
/* create a prepared statement */
$stmt = $conn->stmt_init();
// prepare and bind
if($stmt = $conn->prepare("SELECT id, siteName, workPlace, situation FROM sertkatestdatabase.buildingsite JOIN userworkssites ON sertkatestdatabase.userworkssites.userId=? WHERE sertkatestdatabase.buildingsite.id=sertkatestdatabase.userworkssites.buildingsiteId"))
{
$stmt->bind_param("i", $id);
// execute query
$stmt->execute();
// bind result variables //
$stmt->bind_result($resultId,$resultSiteName,$resultWorkPlace,$resultSituation);
// fetch value //
while ( $stmt->fetch() )
{
$list[]=array('id' => $resultId, 'siteName' => $resultSiteName, 'workPlace'=>$resultWorkPlace, 'situation'=>$resultSituation);
//array_push($list,array('id' => 1, 'siteName' => 'test', 'workPlace'=>'test', 'situation'=>'test'));// I also try this. It doesn't work.
}
// close statement
$stmt->close();
}
$conn->close();
// Create List
$myList = array('list'=>$list);
return $myList;
}
by looking at the code,
The 3rd complex type "UserSiteList" is not required.
Also you can append elements to the $myList array using,
array_push($myList,$list); //inside while loop
Please refer to the following sample code which returns the array of Employee structs,
<?php
require_once "lib/nusoap.php";
function getEmployees($city){
error_reporting(E_ALL & ~E_NOTICE);
$arrayOfEmployees = array();
$employeeArray1 = array();
$employeeArray1['ID'] = 1;
$employeeArray1['NAME'] = "Robert";
$employeeArray1['City'] = "Newyork";
array_push($arrayOfEmployees,$employeeArray1);
$employeeArray2 = array();
$employeeArray2['ID'] = 2;
$employeeArray2['NAME'] = "Micheal";
$employeeArray2['City'] = "Newyork";
array_push($arrayOfEmployees,$employeeArray2);
$employeeArray3 = array();
$employeeArray3['ID'] = 3;
$employeeArray3['NAME'] = "David";
$employeeArray3['City'] = "Washington";
array_push($arrayOfEmployees,$employeeArray3);
$employeeArray4 = array();
$employeeArray4['ID'] = 3;
$employeeArray4['NAME'] = "Andy";
$employeeArray4['City'] = "Newyork";
array_push($arrayOfEmployees,$employeeArray4);
//filter employees by city
foreach($arrayOfEmployees as $elementKey => $element) {
foreach($element as $valueKey => $value) {
if($valueKey == 'City' && $value != $city){
unset($arrayOfEmployees[$elementKey]);
}
}
}
return $arrayOfEmployees;
}
$server = new soap_server();
$namespace = 'http://localhost/test_soap_service/get_employee_list.php?WSDL';
$server->configureWSDL('GetEmployeesService', $namespace);
//create a complex type for Employee
$server->wsdl->addComplexType('Employee','complexType','struct','all','',
array(
'ID' => array('name' => 'ID','type' => 'xsd:int'),
'NAME' => array('name' => 'NAME','type' => 'xsd:string'),
'Age' => array('name' => 'Age','type' => 'xsd:int')
)
);
//create a complex type for Array of Employees
$server->wsdl->addComplexType(
'arrayOfEmployees',
'complexType',
'array',
'',
'SOAP-ENC:Array',
array(),
array(
array(
'ref' => 'SOAP-ENC:arrayType',
'wsdl:arrayType' => 'tns:Employee[]'
)
)
);
$server->register("getEmployees",
array('city' => 'xsd:string'),
array('return' => 'tns:arrayOfEmployees')
);
if ( !isset( $HTTP_RAW_POST_DATA ) ) $HTTP_RAW_POST_DATA =file_get_contents( 'php://input' );
$server->service($HTTP_RAW_POST_DATA);
?>
I'm building json sub-array structure (from CSV) using the following PHP:
$tracks = array();
foreach ($result['tracks'] as $trackdata) {
$songId = $trackdata['songId'];
$title = $trackdata['title'];
$ISRC = $trackdata['ISRC'];
$name1 = $trackdata['artists:name[1]'];
$name2 = $trackdata['artists:name[2]'];
$main1 = $trackdata['artists:main[1]'];
$main2 = $trackdata['artists:main[2]'];
$tracks['tracks'][] = array(
'songId' => $songId,
'title' => $title,
'ISRC' => $ISRC,
'artists' => array(
0 => array(
'name' => $name1,
'main' => (boolean) $main1
),
1 => array(
'name' => $name2,
'main' => (boolean) $main2
)
)
);
}
Currently, if the CSV contains empty values the json (correctly) displays the value as NULL.
What would I need to add to my PHP to stop a particular object from being part of the json if its value is empty / blank?
I'm specifically looking to not print artists:name[2] and artists:main[2] if a second artists doesn't exist in the CSV data.
Here is an example of the CSV code:
"trk-04","track 4","USAM18490006","John Smith",true,,
I've researched (and attempted to implement) if (empty... but I'm not sure where that would come in this code.
Any pointers would be great.
Thanks in advance!
You will want to avoid adding the second artist to the intermediate array that you subsequently json-encode.
$tracks = array();
foreach ($result['tracks'] as $trackdata) {
$songId = $trackdata['songId'];
$title = $trackdata['title'];
$ISRC = $trackdata['ISRC'];
$name1 = $trackdata['artists:name[1]'];
$name2 = $trackdata['artists:name[2]'];
$main1 = $trackdata['artists:main[1]'];
$main2 = $trackdata['artists:main[2]'];
$artists = array();
// First artist always exists
$artists[] = array('name' => $name1, 'main' => (boolean) $main1);
// Add second artist only if one exists with a non-null name
if(!is_null($name2)) {
$artists[] = array('name' => $name2, 'main' => (boolean) $main2);
}
$tracks['tracks'][] = array(
'songId' => $songId,
'title' => $title,
'ISRC' => $ISRC,
'artists' => $artists
);
}
You can use the empty function instead of is_null if you wish. It will consider names such as empty strings and the number 0 as not existing. is_null will only catch those which are strictly === null.
like this :
if (!empty($songId))
{
$tracks['tracks']['songId'] = $songId;
}
if (!empty($title))
{
$tracks['tracks']['title'] = $title;
}
and so on ...
$artists[0] = array(
'name' => $name1,
'main' => (boolean) $main1
);
if (!empty($name2)&&!empty($main2))
$artists[1] = array(
'name' => $name2,
'main' => (boolean) $main2
);
$tracks['tracks'][] = array(
'songId' => $songId,
'title' => $title,
'ISRC' => $ISRC,
'artists' => $artists
);
use array_filter to filter out unset date from an array
// assuming $artist is an array you want to scrub
$artist = array_filter($artist);
$track["artists"][] = $artist;
if ( ( ! isset( artists:name[2] ))
|| ( empty( artists:name[2] ))
) {
unset( $tracks['tracks'][ 'artists' ][ 1 ] );
}
Better
$n = 0;
while( ! empty( $trackdata[ 'artists:name[' . $n+1 . ']' ] )) {
$tracks['tracks'][ 'artists' ][ $n ][ 'name' ]
= $trackdata[ 'artists:name[' . $n+1 . ']' ];
$tracks['tracks'][ 'artists' ][ $n ][ 'main' ]
= $trackdata[ 'artists:main[' . $n+1 . ']' ];
$n++;
}
i have a problem returning an array of arrays, i making a web service in php using nusoap, here is my code:
server.php
<?php
//libreria de nusoap
require_once ('nusoap/lib/nusoap.php');
$miURL = 'http://localhost/webservice/';
$server = new soap_server();
$server->configureWSDL('Web Service de Pruebas', $miURL);
$server->wsdl->schemaTargetNamespace = $miURL;
$server->wsdl->addComplexType(
'array_php',
'complexType',
'struct',
'all',
'',
array(
'pk' => array('name' => 'pk', 'type' =>'xsd:int'),
'rol' => array('name' => 'rol', 'type' =>'xsd:string'),
'descripcion' => array('name' => 'descripcion', 'type' =>'xsd:string')
)
);
$server->wsdl->addComplexType(
'array_array',
'complexType',
'array',
'',
'SOAP-ENC:Array',
array(),
array(
array('ref' => 'SOAP-ENC:arrayType',
'wsdl:arrayType' => 'tns:array_php[]'
)
),
'tns:array_php'
);
$server->register('prueba', // method name
array(), // input parameters
array('return' => 'tns:array_array'), // output parameters
$miURL, // namespace
$miURL . '#prueba', // soapaction
'rpc', // style
'encoded', // use
'Get Specific array_php' // documentation
);
function prueba()
{
$con = mysql_connect('localhost', 'root', '1234');
mysql_selectdb('laboral', $con);
$sql = "SELECT * FROM roles";
$q = mysql_query($sql);
$item = array();
while($r = mysql_fetch_assoc($q)){
$item[] = $r;
}
return $item;
}
if( !isset($HTTP_RAW_POST_DATA) )
$HTTP_RAW_POST_DATA = file_get_contents( 'php://input' );
$server->service($HTTP_RAW_POST_DATA);
?>
client.php
<?php
//libreria nusoap
require_once ('nusoap/lib/nusoap.php');
//lineas de configuracion
$serverURL = 'http://localhost/webservice/ws2.php?wsdl';
$cliente = new nusoap_client($serverURL);
//sí error de conexión:
$error = $cliente->getError();
if($error){
echo "<p> '.$error.' </p>";
echo '<p style="color:red;'>htmlspecialchars($cliente->getDebug(), ENT_QUOTES).'</p>';
die();
}
echo "<br/>";
$arreglo2 = $cliente->call('prueba');
echo "<br/>";
for( $i=0; $i<3; $i++ ){
print_r( $arreglo2[$i]['pk'] );
print_r( $arreglo2[$i]['rol'] );
print_r( $arreglo2[$i]['descripcion'] );
echo "<br/>";
}
?>
the problem is the return, is returning nothing to my client and i dont know what happens, i been reading a lot of forums but i cant find a answer, please if some one know about help me here
ty and sorry for my english
This is what I did:
// Complex Array Keys and Types ++++++++++++++++++++++++++++++++++++++++++
$server->wsdl->addComplexType('notaryConnectionData','complexType','struct','all','',
array(
'id' => array('name'=>'id','type'=>'xsd:int'),
'name' => array('name'=>'name','type'=>'xsd:string')
)
);
// *************************************************************************
// Complex Array ++++++++++++++++++++++++++++++++++++++++++
$server->wsdl->addComplexType('notaryConnectionArray','complexType','array','','SOAP-ENC:Array',
array(),
array(
array(
'ref' => 'SOAP-ENC:arrayType',
'wsdl:arrayType' => 'tns:notaryConnectionData[]'
)
)
);
// *************************************************************************
// This is where I register my method and use the notaryConnectionArray
$server->register("listNotaryConnections",
array('token' => 'xsd:string'),
array('result' => 'xsd:bool', 'notary_array' => 'tns:notaryConnectionArray', 'error' => 'xsd:string'),
'urn:closingorder',
'urn:closingorder#listNotaryConnections',
'rpc',
'encoded',
'Use this service to list notaries connected to the signed-in title company.');
// In my function, I query the data and do:
$list = array();
$results = mysql_query($query);
while($row = mysql_fetch_assoc($results)) {
array_push($list, array('id' => intval($row['na_id']), 'name' => $row['agency_name']));
}
return array("result" => true, "notary_array" => $list);
// The output is:
Array
(
[result] => 1
[notary_array] => Array
(
[0] => Array
(
[id] => 1
[name] => Agency 1
)
[1] => Array
(
[id] => 3
[name] => Agency 3
)
[2] => Array
(
[id] => 4
[name] => Agency 4
)
)
[error] =>
)
Hope this helps.