Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Looking at your full code from <a href="http://pastebin.com/40TQFEd5" rel="nofollow noreferrer">http://pastebin.com/40TQFEd5</a>, it's clear you don't understand how the PHP process flow works. In short, every time a page is loaded (either by GET or POST), it's like your program is starting from scratch. The only way data is preserved between separate page loads is if you explicitly store it somewhere to be preserved - such as in a server-side SESSION variable, or client side: * output it in a link so it can be picked up in a GET variable * output a form field (eg, hidden field) so it can be picked up in a GET or POST variable (depending on form submission method) * call SetCookie() or output javascript that sets a cookie so it can be picked up in a COOKIE variable</p> <p>The relevant bit of code:</p> <pre><code> if ($_POST['new_page']) { print "&lt;h2&gt;Create new page&lt;/h2&gt;\n"; $this-&gt;EditForm(true); } else if($_POST['edit']){ print "&lt;h2&gt;Edit page&lt;/h2&gt;\n"; $this-&gt;EditForm(false); } else if($_POST['save']){ $this-&gt;SaveChanges($_POST['author'], $_POST['org_id'], $_POST['title'], $_POST['content'],$this-&gt;isNew); $this-&gt;DefaultForm(); </code></pre> <p>Aside from the problems that you're not even setting the $isNew variable in your code example, the real problem is that the flow works like this:</p> <ul> <li>Page is loaded, with the POST value 'edit' or 'new_page'. A new instance of <code>HTMLEditor</code> class is created, and (though your code doesn't actually do this now) $isNew is set appropriately based on the POST value. Form is output to page, and sent to client</li> <li>User fills out form in browser, and hits submit</li> <li>Page is loaded, with the POST value 'save'. A new instance of <code>HTMLEditor</code> class is created. <strong>isSet is unknown, since it was not preserved and sent to the server again.</strong></li> </ul> <p>So simple solution: in your <code>EditForm()</code> method, output a hidden field that includes the isSet value, or even better, the post ID value.</p> <hr> <p>As an aside, your code can use some work. There is at least one SQL injection vulnerability:</p> <pre><code>$sql.=" AND pages.ID = '".$_POST['pageID']."'"; </code></pre> <p>Indenting your print statements based on HTML makes it hard to read the code:</p> <pre><code> print "&lt;table width=\"100%\"summary=\"New Page\"\n&gt;"; print "&lt;tr&gt;\n"; print "&lt;th&gt;Author: &lt;/th&gt;\n"; print "&lt;td&gt;&lt;input type=\"text\" name=\"author\""; if(isset($row['Name'])){ print "value=\"".$row['Name']."\""; } print "/&gt;&lt;/td&gt;\n"; </code></pre> <p>and indeed, having that much form output shown as print statements is hard to read and maintain. I'd suggest you look into a template engine: See <a href="https://stackoverflow.com/questions/62617/whats-the-best-way-to-separate-php-code-and-html">https://stackoverflow.com/questions/62617/whats-the-best-way-to-separate-php-code-and-html</a> or <a href="https://stackoverflow.com/questions/62605/php-as-a-template-language-or-some-other-php-templating-script">https://stackoverflow.com/questions/62605/php-as-a-template-language-or-some-other-php-templating-script</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload