title: MySQL, PHP and failing UPDATE Command
body: <p>I am experiencing something so basic, yet so annoying that I thought I had to put it out to the wider community to save my sanity.
  I am using a table within a database to store some very basic data. There is only two columns, Id and Campaign. I only want to use a single row of the table, however, campaign will be updated at various points. I have set up the table as follows:</p>
  
  <pre><code>$sql = "CREATE TABLE IF NOT EXISTS TestCampaign(id INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
  Campaign CHAR(20))";
  </code></pre>
  
  <p>Initially I write to the table to insert a null CHAR in campaign:</p>
  
  <pre><code>$sql = "INSERT INTO TestCampaign (Campaign) VALUES ('None')";
  </code></pre>
  
  <p>The based on a specific text field being filled in on an html form followed by a submit button press I intended to do the update of the campaign field:</p>
  
  <pre><code>$sql = "UPDATE TestCampaign SET Campaign = '$Test' WHERE id = '1'";
  </code></pre>
  
  <p>$Test is the POSTED campaign name from the form. Unfortunately although the INSERT works fine the UPDATE doesn't. I have checked the permissions and I have ALL on this database. I have also checked the syntax with various sites and it seems that it is fine. </p>
  
  <p>Interestingly I do not get an error when I echo:</p>
  
  <pre><code>echo " ".mysqli_error($con);
  </code></pre>
  
  <p>I'm sure I have made some basic error somewhere but I have been looking at it for so long and changing the syntax that I can't seem to spot it.
  Any help would be appreciated. </p>
  
  <p>UPDATE:
  I have played around with the code and it seems as though the UPDATE code does work, however, It only works when it is the next line of code after the INSERT. In fact I have found that it works as long as it is not where I need it to be. I have it placed in 'if' statement that is run only on a specific button press on the form:</p>
  
  <pre><code>if(isset($_POST['TestID']))
   {
    Some Code;
    $sql = "UPDATE TestCampaign SET Campaign = '$Test' WHERE id = '1'";
    Some More Code;
   }
  </code></pre>
  
  <p>I have checked the rest of the code in the 'if' statement and it seems solid.</p>
  
  <p>Is this odd behaviour or have I missed something?</p>
  
  <p><strong>SOLVED</strong>
  Finally found out what the problem was, it ended up that when exiting the first 'if' statement as expected the html form code was revisited which must have closed the connection to the database, when the button was pressed to run the second 'if' statement there was a connection to MySQL but no connection to the database I needed access to. A quick fix to re-connect and all works fine. </p>