php,smartyRelated issues-Collection of common programming errors
flem
php javascript jquery
I have a couple form elements that when clicked update the database and disappear.At first, I have a button that reads Check In. Upon clicking it, the database is updated and a dropdown is presented in place of the button. In the dropdown, there are locations for the user to choose, that have values of their corresponding location-number, which upon clicking update the database. The last option is labeled Check Out, and upon clicking it, the database is supposed to be updated one last time, and
Fabien
php scope callback
class myClass {$myVariable = ‘myCallback’;function myFunction() {$body = false;$callback = $this->myVariable;function test($handle, $line) {global $body, $callback;if ($body) {call_user_func($callback, $line);}if ($line === “\r\n”) {$body = true;}return strlen($line);}…curl_setopt($ch, CURLOPT_WRITEFUNCTION, ‘test’);…} }function myCallback($data) {print $data; }$myCls = new myClass(); $myCls->myFunction();Warning: call_user_func() [function.call-user-func]: First argument is expected t
RaphaelDDL
php jquery ajax json-encode parse-error
I’m using PHP’s json_encode() to return some data, retrieved by jQuery’s ajax():Simplified JS:$.ajax({dataType: ‘json’,contentType: ‘application/json’,cache: false,type: ‘POST’,url: ‘./api/_imgdown.php’,error: function(jqXHR, textStatus, errorThrow) {console.log(jqXHR, textStatus, errorThrow);},success: function(data, textStatus, jqXHR) {console.log(data, textStatus, jqXHR);} });The PHP is:header(‘Content-Type: application/json; charset=UTF-8’); //default apiResponse $apiResponse = [“status” =&g
RSM
php if-statement
I have an input text area which when filled out and sent, puts whatever was typed in into the variable$inputThis is then put through an if statement to check whether or not its the letter a. If it is then echo – you wrote the letter a, else – you did not write the letter a. <?php $input = $_POST[“textarea”];echo $input;echo “<br />”;if($input = “a”){echo “You wrote a”;}else{echo “You did not write a”;}?>It does work, but in the wrong way. Every letter I type in comes as ‘You wrote
Thew
php api imgur
i have a question about the imgur api. I want to create a gallery for my website using the imgur api, but how can i create a file uploader that uploads to the imgur servers?Here is what i created:<?php include ‘xmlparser.php’; // From http://www.criticaldevelopment.net/xml/doc.php if($_SERVER[‘REQUEST_METHOD’] == “POST”){$data = file_get_contents($_FILES[“file”][‘tmp_name’]);// $data is file data$pvars = array(‘image’ => base64_encode($data), ‘key’ => HERE_MY_API_KEY);$timeout = 30;$
PeeHaa
php
For example is there a difference between the two? Is one preferred to the other?Class Node{ public $parent = null;public $right = null;public $left = null; function __construct($data){$this->data = $data; } }Class Node{ function __construct($data){$this->data = $data; $this->parent = null; $this->left = null; $this->right = null; } }
T9b
php mysql validation escaping sanitization
I’m just discovering PHPs sanitize and Validate filters, and I had been using MySQL’s mysql_escape_string to stop SQL Injection.Now I discover that PHP can also help and I guess logically these procedures are not exclusive in their function: ie you can sanitize and validate in PHP and still arrive at a situation where escaping is necessary.Am I right or am I overlooking something?
Chris Allington
php mysql
I have created a real estate website and I wanted to have the listings sorted by the last update and completeness of the listing. So I have been trying to figure out how to sort by a field in mysql (completion_score) in combination with the most recently updated listing. The completion score would be on a 100 point scale with 0 being bad and 100 being perfectly complete. I will have the completion score calculated when the listing is added and updated and saved in the mysql database. I am guessi
j0k
php forms symfony2
I have an entity type form field in my Symfony2 project. $builder = $this->createFormBuilder(); $projects = $this->getProjects();$builder->add(‘project’, ‘entity’,array(‘class’ => ‘OpexMarketOPEXMOPEXBundle:Project’,’required’ => false,’choices’ => $projects,));The problem I’m having is, when the getProjects() method will return an empty result set, the drop down list will have all the projects in the Project table.Is there any way to disable this behavior?
Clement Herreman
php symfony1 doctrine persistence many-to-many
Today I met some unexpected behavior on doctrine (1.2). SituationI’ve a Document class, and an Anomaly class. A Document can have many Anomalies, and an Anomaly can be found on many Documents.#schema.ymlDocument:columns:id: { type: integer(12), primary: true, autoincrement: true }scan_id: { type: integer(10), notnull: true }name: { type: string(100), notnull: true }Anomaly:columns:id: { type: integer(5), primary: true, autoincrement: true }label: { type: string(200) }value: { ty
Daryl Gill
php smarty
I’m in the process of creating a controller to display pages. I currently have this; $request = str_replace(“/Smarty/”, “”, $_SERVER[‘REQUEST_URI’]); $params = explode(“/”, $request); function FormatArr ($Arr){$Array_Keys = array (“PageName”,”Username”);if (count($Arr) > 2){trigger_error(“Unexpected Params”,E_USER_ERROR);}return array_combine($Array_Keys,$Arr);}$New_Params = FormatArr($params);On the setup.php page, then on my libs: class testing {protected $Smarty;protected $fixpath;public
ShoeLace1291
codeigniter parsing smarty
So, my friend that owns the domain that we are working on set up a live development server for me to upload my files to. I had previously been developing on WAMP. I uploaded the CodeIgniter files to the web server(along with the application) and updated the config files. When everything in the config was working, I refreshed the page and got an error. Parse error: syntax error, unexpected T_STRING in /blah/blah/html/application/frontend/views/overall_header.tpl on line 1This is the very firs
user1132887
smarty
I have written the header.tpl and login.php file in smarty. i want to show the logout text if user is logged in. otherwise it should show login if user is not logged in.below is the code of login.phpif(isset($_REQUEST[‘submit’])){$name=$_REQUEST[‘name’];$pass=$_REQUEST[‘pass’];$rs=mysql_query(“select * from form where name=’$name'”);$fetchdata=mysql_fetch_array($rs); if($rs){$name=$fetchdata[‘name’]$_SESSION[‘name’]=$name;$name1=$_SESSION[‘name’];//$smarty->assign(‘name’,$_SESSION[‘name’]
Kestion
smarty prestashop
I’m trying to add a new google analytics event in a form. So I have something like this : <a href=”#” name=”button1″ onclick=”dataLayer.push({‘event’: ‘button1-click’});” >Button 1</a>So far, so good. But I get this weird smarty error : Fatal error: Uncaught exception ‘SmartyCompilerException’ with message ‘Syntax Error in template “C:\wamp\www\mycookit/themes/cookit/delivery.tpl” on line 164 “dataLayer.push({‘event’: ‘event_name’});” – Unexpected “: “, expected one of: “}” , ” “‘ i
sathia
php smarty
If I try to assign a multidimensional array to a class i get this error {Widgets->Widgetmedia=’videos’filters=Array(‘a’ => ‘b’, ‘c’ => ‘d’)}”{assign var=’X’ value = Array(‘a’ => ‘b’, ‘c’ => ‘d’)}” – Unexpected ” => “, expected one of: “”,”” , “)”‘this doesn’t work as wellfilters[‘a’]=’b’filters[‘c’] = ‘d’is there a way to circumvent this limit? the version of smarty I’m using is the latest.the documentation isn’t very clear about it: http://www.smarty.net/docs/en/advan
Paul Rusu
php smarty whmcs
I have added the function.bnr_exchange.php to the includes/smarty/plugins directory. It contains smarty_function_bnr_exchange which returns a string.I also modified invoicepdf.tpl $pdf->Cell(0,6,{bnr_exchange} . ”,0,1,’L’,’1′);which gives error: unexpected { I tried with “{bnr_exchange}” but then it writes the text {bnr_exchange}If i simply write {bnr_exchange} in the template it says unexpected } in that line. So it doesn’t recognize the plugin “bnr_exchange”. My question is how do I tell w
Claude Grecea
php pdo smarty
I am having a problem with Smarty passing a PDO Object to Smarty it just doesn’t like =>. Is there a trick to get around this problem?Here is he error:{assign var=’brgdatas’ value=”{$brgObj->fetchOneBrg(array(‘id’=>{$ststres[ststval].to_id}’))}”}” – Unexpected “=>”, expected one of: “”,”” , “)Here is the code I am working with:{section name=ststval loop=$ststres}{if $ststres[ststval].type == 2}{assign var=’brgdatas’ value=”{$brgObj->fetchOneBrg(array(‘id’=>{$ststres[ststval].to
Jerielle
javascript jquery smarty
Hello guys I have a problem in getting textboxes inputs in my jquery using ID. Ok here’s my code.<script type=”text/javascript”>var globalBase_Url = “{$base_url}”; //OK NO ERROR var name = “”;var desc = “”;{literal}$(document).ready(function(){$(‘#add_cat’).on(‘click’,function(){$(‘#add_category’).show(‘slide’);});$(‘#submit’).on(‘click’,function(){jquery.ajax({ var name = $(‘#category_name’).val(); //this is the errorvar desc = $(‘#description’).val(); // this is the error});});});{/li
NemoPS
jquery ajax smarty
I need to output a couple of lines of escaped html using ajax, with the object being generated by smarty. However, I keep getting unexpected token even if I used both nl2br and |regex_replace:’/[\r\n]/’ : ‘<br/>’.Here is the troublesome code:”value”: “<div class="ps-header-links"><br/> <br/> <ul><br/> <li><a href="http://prestashop.com" ti
j0k
javascript smarty prestashop
I’m developing a Prestashop website, and I’m getting a “SyntaxError: unterminated string literal” javascript error. The problem is when I get an address, this works nice:,”address1″:”Pza libertad” ,”address2″:”4º 3ª” ,”postcode”:”08905″The problem comes here:,”address1″:”Plaza libertad 3″,”address2″:” 4º3ª”,”postcode”:”08905″This code is generated like this:{foreach from=$type.formated_fields_values key=pattern_name item=field_name name=inv_loop} {if !$smarty.
Web site is in building