Parse error: syntax error, unexpected '[' on line 108
$row->liked_by = $row->liked_by ? explode('|', $row->liked_by) : [];
This is the error i am getting but works fine on the local server. I am trying to run the explode function on hostgator server with PHP 5.3 version.
here's the code for which i am getting this parse error.
while($row = $articlesQuery->fetch_object()) {
$row->liked_by = $row->liked_by ? explode('|', $row->liked_by) : [];
$articles[] = $row;
}
please help
Thanks in advance.
[] notation for arrays is only supported in PHP 5.4+, try this if you're using a lower version :
while($row = $articlesQuery->fetch_object()) {
$row->liked_by = $row->liked_by ? explode('|', $row->liked_by) : array();
$articles[] = $row;
}
Related
i need help to create a function in zkteco php library to change user group
this is my code but its not working,anybody can help me
reference url : https://github.com/adrobinoga/zk-protocol/blob/master/sections/access.md
zklibrary : https://github.com/kamshory/ZKLibrary
`public function userGroup($uid,$gid)
{
$command = CMD_USERGRP_WRQ;
$byte1 = chr((int) ($uid % 256));
$byte2 = chr((int) ($uid >> 8));
$byte3 = chr((int) ($gid));
$command_string = $byte1 . $byte2 . $byte3;
return $this->execCommand($command, $command_string);
}`
this function is not ok i think the $command_string is wrong but i cant rectify the error
Is there a bug or something?
$mpdf = new \Mpdf\Mpdf();
$mpdf->enableImports = true;
$mpdf->debug = true;
$mpdf->SetImportUse();
Call to undefined method Mpdf\Mpdf::SetImportUse() in /home/.../vendor/mpdf/mpdf/src/Strict.php:15
Found out it isn't needed in v8. In addition, importPage has different case than in v7. importPage is the correct one. So solved.
Solution For MPDF8
$pdf = new \Mpdf\Mpdf();
#$pages array with file paths /uploads/file1.pdf, /uploads/file2.pdf...
foreach($pages as $page)
{
$pagecount = $pdf->setSourceFile($page);
$import_page = $pdf->importPage($pagecount);
$size = $pdf->getTemplateSize($import_page);
$orientation = $size['width'] > $size['height'] ? "L" : "P";
$pdf->AddPageByArray(['orientation' => $orientation]);
$pdf->useTemplate($import_page);
}
I am working under perl. I am implementing a dynamic query and I have problems with this stuff , If you could give me a piece of advice during my searching.
Now, my static query:
my $envoi_numfact = $dbh->selectrow_array("SELECT envoi_numfact FROM user.envoi where envoi_reference='hapiness'");
print Dumper($envoi_numfact);
I have a nice result :
$VAR1 = '1611029546';
So I would like to transform it in dynamic query such as :
my $envoi_numfact = $dbh->selectrow_array("SELECT envoi_numfact FROM user.envoi where envoi_reference=?",undef,$hash_infos{ope_ref} );
Where $hash_infos{ope_ref} represents envoi_reference.
As a result, I have :
$VAR1 = undef;
Anyone couls help me ?
I am a winner ! I have just forgotten the closing bracket.
my $envoi_numfact = $dbh->selectrow_array("SELECT envoi_numfact FROM user.envoi where envoi_reference=?",undef,$hash_infos{ope_ref} );
becomes
my $envoi_numfact = $dbh->selectrow_array("SELECT envoi_numfact FROM user.envoi where envoi_reference = ?",undef,($hash_infos{ope_ref}));
I have a problem with a prepared statement, here is my code:
function query_array($table, $data) {
foreach ($data as $column => $value) {
$columns[] = sprintf("`%s` = '%s'", $column, $this->db->real_escape_string($value));
}
$column_list = join(',', $columns);
// Prepare the statement
$stmt = $this->db->prepare("UPDATE `?` SET ?");
$stmt->bind_param('ss', $table, $column_list);
// Execute the statement
$stmt->execute();
// Save the affected rows
$affected = $stmt->affected_rows;
// Close the statement
$stmt->close();
// ...
}
$this->db returns an object;
$table = 'settings'; (string)
$column_list: (string)
`title` = 'Socialsd',`captcha` = '0',`public` = '',`private` = '',`time` = '1',`perpage` = '10',`message` = '140',`mail` = '1',`inter` = '10000',`size` = '1048576',`format` = 'png,jpg,gif',`sizeMsg` = '1048576',`formatMsg` = 'png,jpg,gif,bmp',`censor` = '',`ad1` = '',`ad2` = ''
The error I'm getting is:
Fatal error: Uncaught exception 'ErrorException' with message 'You
have an error in your SQL syntax; check the manual that corresponds to
your MySQL server version for the right syntax to use near '?' at line
1' in C:\xampp\htdocs\new\includes\classes.php:256 Stack trace: #0
C:\xampp\htdocs\new\sources\admin.php(225):
updateSettings->query_array('settings', Array) #1
C:\xampp\htdocs\new\index.php(42): PageMain() #2 {main} thrown in
C:\xampp\htdocs\new\includes\classes.php on line 256
I can't figure out what causes this, because trying the following works just fine:
$query = sprintf("UPDATE `%s` SET %s", $table, $column_list);
$result = $this->db->query($query);
Any help is appreciated.
Update 1: May I know why this has been down-voted? It would be nice to know.
Update 2: So I've removed the last bind ($column_list) and put in the statement the entire output of $column_list, so basically I was binding only the table name, and now I get another error:
Can't find file: '.\diary\#003f.frm' (errno: 22)
Now I'm really confused.
I have found the answer here: Use one bind_param() with variable number of input vars and also as #Jocelyn linked me, I've found that table names can't be binded. Can be closed.
I seem to have a problem with uploadify. It always get stuck at 100% on the first file, no matter what the file is. I am using Zend on my Wamp and it works fine there but as soon as I upload it on my linux server it gets stuck. The file is uploaded and renamed but it never fires the onComplete event and stays at 100% on the first file.
Here is my javascript:
$('#fileInput').uploadify({
'uploader' : 'http://test.thevenuelist.co.uk/js/uploadify/uploadify.swf',
'script' : 'http://test.thevenuelist.co.uk/ajax/uploadify',
'cancelImg' : 'http://test.thevenuelist.co.uk/js/uploadify/cancel.png',
'folder' : '/userdata/images/',
'auto' : true,
'multi' : true,
'fileDesc' : 'Image Files (*.jpg;*.jpeg;*.gif;*.png)',
'fileExt' : '*.jpg;*.jpeg;*.gif;*.png',
'buttonText' : 'Upload Images',
'removeCompleted' : true,
'onComplete' : function (event, queueID, fileObj, response, data) {
var answer = eval('(' + response + ')');
if(answer.result == "success")
{
$("#hdnImages").val($("#hdnImages").val() + answer.fileName + ",");
var toAdd = "<li><img src='/images/delete.png' id='removeItem' rel='"+answer.fileName+"' style='cursor:pointer;' title='Remove' alt='Remove'/> Image "+answer.realName+" uploaded</li>";
$("#completedItemsList").append(toAdd);
}
},
'onError': function (event, queueID ,fileObj, errorObj) {
alert(errorObj.info);
}
});
And here is my Zend code behind:
$tempFile = $_FILES['Filedata']['tmp_name'];
$targetPath = $_SERVER['DOCUMENT_ROOT']. '/' . $_REQUEST['folder'] . '/';
$fileNameArray = explode('.',$_FILES['Filedata']['name']);
$hash = substr(md5(microtime()),0,5);
$finalFileName = $fileNameArray[0].$hash.'.'.$fileNameArray[1];
$targetFile = str_replace('//','/',$targetPath) . $finalFileName;
if(move_uploaded_file($tempFile,$targetFile))
{
$data = array("result"=>"success","fileName"=>$finalFileName,"realName"=>$_FILES['Filedata']['name']);
}
else
{
$data = array("result"=>"failed");
}
echo Zend_Json::encode($data);
Any help would be greatly appreciated. I have spent way too much time trying to figure it out. I need my onComplete event to work so I can finish my forms.
I found with uploadify I had to return either a 1 or a 0 for success or failure to get it to work.