Sunday 15 June 2014

PHP template with function -


I have found a function that has displayed its value on the html page but it will not work.

PHP Code:

  $ template = file_get_contents ("main.tpl.php"); Function Update Form ($ ID) {$ query = "Select * Plate to WHERE ID =". $ Id; $ Result = mysql_query ($ query) or die (mysql_error ()); While ($ line = mysql_fetch_array ($ result)) {$ editForm = "& lt; form action = 'index.php? Update & amp; id =" $ line [' id ']. '' Method = 'post' & gt; "; $ EditForm. =" & Lt; Label = 'id' & gt; & Lt; Span & gt; ID: & lt; / Span & gt; & Lt; / Labels & gt; & Lt; Input name = 'id' id = 'id' type = 'text' value = '". $ Line [' id '].' '& Gt; & lt; / br & gt;"; $ EditForm = 'Album' & gt; & lt; span & gt; Album: & lt; / span & gt; & lt; / Label & gt; & lt; Input Name = 'Album' ID for label = "& lt; = 'Album' type = 'text' value = '". $ Line ['album']. '' & Gt; & Lt; / Br & gt; "; $ EditForm. =" & Lt; Label = 'for band' & gt; Band: & lt; / Labels & gt; & Lt; Input name = 'band' id = 'band' type = 'text' value = ''. $ Line ['band'] '' & Gt; & Lt; / Br & gt; "; $ EditForm. =" & Lt; Label for = 'stijl' & gt; Stijl: & lt; / Labels & gt; & Lt; Input name = 'stijl' id = 'stijl' type = 'text' value = ''. $ Line ['style']. '' & Gt; & Lt; / Br & gt; "; $ EditForm. =" & Lt; For label = 'medium' & gt; Medium: & lt; / Label & gt; & Lt; Input name = 'medium' id = 'medium' type = 'text' value = ''. $ Line ['medium']. '' & Gt; & Lt; / Br & gt; "; $ EditForm. =" & Lt; Label for = 'datum' & gt; Data: & lt; / Label & gt; & Lt; Input name = 'datum' id = 'datum' type = 'text' value = ''. $ Line ['data'] '' & Gt; & Lt; / Br & gt; "; $ EditForm. =" & Lt; Label = 'prijs' for & gt; Prijs: & lt; / Labels & gt; & Lt; Input name = 'prijs' id = 'prijs' type = 'text' value = ''. $ Line ['prze'] '' & Gt; & Lt; / Br & gt; "; $ EditForm. =" & Lt; Input class = 'submit' type = 'submit' value = 'update' & gt; "$ EditForm. =" & Lt; / Form & gt; "} $ Template = str_replace (" %% editForm %% ", $ editForm, $ template);} $ template echo;   

In the My HTML file, % EditForm %% is available but when I try to do it, it says that the $ template is undefined. Hope you can help me or find another solution to display data in the HTML file. .

It says $ template is undefinded because it is not visible from the function Enter $ template in the function or add global $ template; inside your function:

  function update form ($ id) {global $ template; $ Query = "Select * Plate to WHERE id =". $ Id;    

No comments:

Post a Comment