{"id":3570,"date":"2014-03-28T11:01:44","date_gmt":"2014-03-28T11:01:44","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/03\/28\/phpsmartyrelated-issues-collection-of-common-programming-errors\/"},"modified":"2014-03-28T11:01:44","modified_gmt":"2014-03-28T11:01:44","slug":"phpsmartyrelated-issues-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/03\/28\/phpsmartyrelated-issues-collection-of-common-programming-errors\/","title":{"rendered":"php,smartyRelated issues-Collection of common programming errors"},"content":{"rendered":"<ul>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/518bacf2e4ad4e4b8f026f6497221fed?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nflem<br \/>\nphp javascript jquery<br \/>\nI 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<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/9f6dfb6c18bce2c8487312b77c32dbc3?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nFabien<br \/>\nphp scope callback<br \/>\nclass myClass {$myVariable = &#8216;myCallback&#8217;;function myFunction() {$body = false;$callback = $this-&gt;myVariable;function test($handle, $line) {global $body, $callback;if ($body) {call_user_func($callback, $line);}if ($line === &#8220;\\r\\n&#8221;) {$body = true;}return strlen($line);}&#8230;curl_setopt($ch, CURLOPT_WRITEFUNCTION, &#8216;test&#8217;);&#8230;} }function myCallback($data) {print $data; }$myCls = new myClass(); $myCls-&gt;myFunction();Warning: call_user_func() [function.call-user-func]: First argument is expected t<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/7536d8aaec4cce943c647002093748e2?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nRaphaelDDL<br \/>\nphp jquery ajax json-encode parse-error<br \/>\nI&#8217;m using PHP&#8217;s json_encode() to return some data, retrieved by jQuery&#8217;s ajax():Simplified JS:$.ajax({dataType: &#8216;json&#8217;,contentType: &#8216;application\/json&#8217;,cache: false,type: &#8216;POST&#8217;,url: &#8216;.\/api\/_imgdown.php&#8217;,error: function(jqXHR, textStatus, errorThrow) {console.log(jqXHR, textStatus, errorThrow);},success: function(data, textStatus, jqXHR) {console.log(data, textStatus, jqXHR);} });The PHP is:header(&#8216;Content-Type: application\/json; charset=UTF-8&#8217;); \/\/default apiResponse $apiResponse = [&#8220;status&#8221; =&amp;g<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/c374825321e77691cd81b242776d250d?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nRSM<br \/>\nphp if-statement<br \/>\nI 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 &#8211; you wrote the letter a, else &#8211; you did not write the letter a. &lt;?php $input = $_POST[&#8220;textarea&#8221;];echo $input;echo &#8220;&lt;br \/&gt;&#8221;;if($input = &#8220;a&#8221;){echo &#8220;You wrote a&#8221;;}else{echo &#8220;You did not write a&#8221;;}?&gt;It does work, but in the wrong way. Every letter I type in comes as &#8216;You wrote<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/03c51d4dacea73644b28b9ece8e84d63?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nThew<br \/>\nphp api imgur<br \/>\ni 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:&lt;?php include &#8216;xmlparser.php&#8217;; \/\/ From http:\/\/www.criticaldevelopment.net\/xml\/doc.php if($_SERVER[&#8216;REQUEST_METHOD&#8217;] == &#8220;POST&#8221;){$data = file_get_contents($_FILES[&#8220;file&#8221;][&#8216;tmp_name&#8217;]);\/\/ $data is file data$pvars = array(&#8216;image&#8217; =&gt; base64_encode($data), &#8216;key&#8217; =&gt; HERE_MY_API_KEY);$timeout = 30;$<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/i.stack.imgur.com\/nZEUQ.png?s=32&amp;g=1\" \/><br \/>\nPeeHaa<br \/>\nphp<br \/>\nFor 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-&gt;data = $data; } }Class Node{ function __construct($data){$this-&gt;data = $data; $this-&gt;parent = null; $this-&gt;left = null; $this-&gt;right = null; } }<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/fe0cddef9090d3f081e0cec085b44d11?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nT9b<br \/>\nphp mysql validation escaping sanitization<br \/>\nI&#8217;m just discovering PHPs sanitize and Validate filters, and I had been using MySQL&#8217;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?<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/d0be543ed846d9fac5dec0e2f5875544?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nChris Allington<br \/>\nphp mysql<br \/>\nI 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<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/aee3b44e5f0b4dfa0e2da672897b3751?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nj0k<br \/>\nphp forms symfony2<br \/>\nI have an entity type form field in my Symfony2 project. $builder = $this-&gt;createFormBuilder(); $projects = $this-&gt;getProjects();$builder-&gt;add(&#8216;project&#8217;, &#8216;entity&#8217;,array(&#8216;class&#8217; =&gt; &#8216;OpexMarketOPEXMOPEXBundle:Project&#8217;,&#8217;required&#8217; =&gt; false,&#8217;choices&#8217; =&gt; $projects,));The problem I&#8217;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?<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/a7e904a0b242c8e4194abff1724ee212?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nClement Herreman<br \/>\nphp symfony1 doctrine persistence many-to-many<br \/>\nToday I met some unexpected behavior on doctrine (1.2). SituationI&#8217;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<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/i.stack.imgur.com\/EVSS2.jpg?s=32&amp;g=1\" \/><br \/>\nDaryl Gill<br \/>\nphp smarty<br \/>\nI&#8217;m in the process of creating a controller to display pages. I currently have this; $request = str_replace(&#8220;\/Smarty\/&#8221;, &#8220;&#8221;, $_SERVER[&#8216;REQUEST_URI&#8217;]); $params = explode(&#8220;\/&#8221;, $request); function FormatArr ($Arr){$Array_Keys = array (&#8220;PageName&#8221;,&#8221;Username&#8221;);if (count($Arr) &gt; 2){trigger_error(&#8220;Unexpected Params&#8221;,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<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/d3c16ac46cd104d54316935eb9e4e973?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nShoeLace1291<br \/>\ncodeigniter parsing smarty<br \/>\nSo, 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<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/6064f505653856710b202e8e17e0e76a?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nuser1132887<br \/>\nsmarty<br \/>\nI 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[&#8216;submit&#8217;])){$name=$_REQUEST[&#8216;name&#8217;];$pass=$_REQUEST[&#8216;pass&#8217;];$rs=mysql_query(&#8220;select * from form where name=&#8217;$name'&#8221;);$fetchdata=mysql_fetch_array($rs); if($rs){$name=$fetchdata[&#8216;name&#8217;]$_SESSION[&#8216;name&#8217;]=$name;$name1=$_SESSION[&#8216;name&#8217;];\/\/$smarty-&gt;assign(&#8216;name&#8217;,$_SESSION[&#8216;name&#8217;]<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/d33f875b2529d5c81c5aab20ee86ca54?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nKestion<br \/>\nsmarty prestashop<br \/>\nI&#8217;m trying to add a new google analytics event in a form. So I have something like this : &lt;a href=&#8221;#&#8221; name=&#8221;button1&#8243; onclick=&#8221;dataLayer.push({&#8216;event&#8217;: &#8216;button1-click&#8217;});&#8221; &gt;Button 1&lt;\/a&gt;So far, so good. But I get this weird smarty error : Fatal error: Uncaught exception &#8216;SmartyCompilerException&#8217; with message &#8216;Syntax Error in template &#8220;C:\\wamp\\www\\mycookit\/themes\/cookit\/delivery.tpl&#8221; on line 164 &#8220;dataLayer.push({&#8216;event&#8217;: &#8216;event_name&#8217;});&#8221; &#8211; Unexpected &#8220;: &#8220;, expected one of: &#8220;}&#8221; , &#8221; &#8220;&#8216; i<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/3678e4fddd885112cd01763e2afcf8ee?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nsathia<br \/>\nphp smarty<br \/>\nIf I try to assign a multidimensional array to a class i get this error {Widgets-&gt;Widgetmedia=&#8217;videos&#8217;filters=Array(&#8216;a&#8217; =&gt; &#8216;b&#8217;, &#8216;c&#8217; =&gt; &#8216;d&#8217;)}&#8221;{assign var=&#8217;X&#8217; value = Array(&#8216;a&#8217; =&amp;gt; &#8216;b&#8217;, &#8216;c&#8217; =&amp;gt; &#8216;d&#8217;)}&#8221; &#8211; Unexpected &#8221; =&gt; &#8220;, expected one of: &#8220;&#8221;,&#8221;&#8221; , &#8220;)&#8221;&#8216;this doesn&#8217;t work as wellfilters[&#8216;a&#8217;]=&#8217;b&#8217;filters[&#8216;c&#8217;] = &#8216;d&#8217;is there a way to circumvent this limit? the version of smarty I&#8217;m using is the latest.the documentation isn&#8217;t very clear about it: http:\/\/www.smarty.net\/docs\/en\/advan<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/a9f08c4ce7e43b2bf332357d84efb857?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nPaul Rusu<br \/>\nphp smarty whmcs<br \/>\nI 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-&gt;Cell(0,6,{bnr_exchange} . &#8221;,0,1,&#8217;L&#8217;,&#8217;1&#8242;);which gives error: unexpected { I tried with &#8220;{bnr_exchange}&#8221; 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&#8217;t recognize the plugin &#8220;bnr_exchange&#8221;. My question is how do I tell w<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/d27f97e2545cba135fb1b7ceb077dc11?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nClaude Grecea<br \/>\nphp pdo smarty<br \/>\nI am having a problem with Smarty passing a PDO Object to Smarty it just doesn&#8217;t like =&gt;. Is there a trick to get around this problem?Here is he error:{assign var=&#8217;brgdatas&#8217; value=&#8221;{$brgObj-&gt;fetchOneBrg(array(&#8216;id&#8217;=&gt;{$ststres[ststval].to_id}&#8217;))}&#8221;}&#8221; &#8211; Unexpected &#8220;=&gt;&#8221;, expected one of: &#8220;&#8221;,&#8221;&#8221; , &#8220;)Here is the code I am working with:{section name=ststval loop=$ststres}{if $ststres[ststval].type == 2}{assign var=&#8217;brgdatas&#8217; value=&#8221;{$brgObj-&gt;fetchOneBrg(array(&#8216;id&#8217;=&gt;{$ststres[ststval].to<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/f016b2c06d0fa6495757c25dc8b37204?s=32&amp;d=identicon&amp;r=PG&amp;f=1\" \/><br \/>\nJerielle<br \/>\njavascript jquery smarty<br \/>\nHello guys I have a problem in getting textboxes inputs in my jquery using ID. Ok here&#8217;s my code.&lt;script type=&#8221;text\/javascript&#8221;&gt;var globalBase_Url = &#8220;{$base_url}&#8221;; \/\/OK NO ERROR var name = &#8220;&#8221;;var desc = &#8220;&#8221;;{literal}$(document).ready(function(){$(&#8216;#add_cat&#8217;).on(&#8216;click&#8217;,function(){$(&#8216;#add_category&#8217;).show(&#8216;slide&#8217;);});$(&#8216;#submit&#8217;).on(&#8216;click&#8217;,function(){jquery.ajax({ var name = $(&#8216;#category_name&#8217;).val(); \/\/this is the errorvar desc = $(&#8216;#description&#8217;).val(); \/\/ this is the error});});});{\/li<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/f8e2e57e9153e1a01b0f834dfe8dd402?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nNemoPS<br \/>\njquery ajax smarty<br \/>\nI 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:&#8217;\/[\\r\\n]\/&#8217; : &#8216;&lt;br\/&gt;&#8217;.Here is the troublesome code:&#8221;value&#8221;: &#8220;&amp;lt;div class=&amp;quot;ps-header-links&amp;quot;&amp;gt;&lt;br\/&gt; &lt;br\/&gt; &amp;lt;ul&amp;gt;&lt;br\/&gt; &amp;lt;li&amp;gt;&amp;lt;a href=&amp;quot;http:\/\/prestashop.com&amp;quot; ti<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/aee3b44e5f0b4dfa0e2da672897b3751?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nj0k<br \/>\njavascript smarty prestashop<br \/>\nI&#8217;m developing a Prestashop website, and I&#8217;m getting a &#8220;SyntaxError: unterminated string literal&#8221; javascript error. The problem is when I get an address, this works nice:,&#8221;address1&#8243;:&#8221;Pza libertad&#8221; ,&#8221;address2&#8243;:&#8221;4&amp;ordm; 3&amp;ordf;&#8221; ,&#8221;postcode&#8221;:&#8221;08905&#8243;The problem comes here:,&#8221;address1&#8243;:&#8221;Plaza libertad 3&#8243;,&#8221;address2&#8243;:&#8221; 4&amp;ordm;3&amp;ordf;&#8221;,&#8221;postcode&#8221;:&#8221;08905&#8243;This code is generated like this:{foreach from=$type.formated_fields_values key=pattern_name item=field_name name=inv_loop} {if !$smarty.<\/li>\n<\/ul>\n<p>Web site is in building<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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, [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-3570","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/3570","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=3570"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/3570\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=3570"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=3570"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=3570"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}