title: How can I php validate my form data so that it has to include content?
body: <p>so I have created a html form that gives the information to the document that holds the html form, and I want a php check to make sure that a particular field has information in it, my code looks like this. </p>
  
  <pre><code>&lt;?php
  if ($_SERVER['REQUEST_METHOD'] == 'POST') {
      $errors = array();
      if ( ! isset($_POST['dbname'])) {
          array_push($errors,'dbname');
      }
          if ( ! isset($_POST['dbpass'])) {
          array_push($errors, 'dbpass');
          }
              if ( ! isset($_POST['dbhost'])) {
          array_push($errors, 'dbhost');
          }
              if ( ! isset($_POST['prefix'])) {
          array_push($errors, 'prefix');
          }
              if (isset($_POST['dbname']) &amp;&amp; trim($_POST['dbname']) != '' {
              echo "something";
              }
              else
              {
              echo "nothing";
              }
  
      if (count($errors) &gt; 0) {
          $error_msg = implode('&lt;br&gt;', $errors);
          show_form($error_msg);
      }
      else {
          do_install();
          echo 'Install Done';
      }
  }
  else {
      // show the form
      show_form();
  }
  </code></pre>
  
  <p>The line that is giving me trouble is</p>
  
  <pre><code>if (isset($_POST['dbname']) &amp;&amp; trim($_POST['dbname']) != ''
  </code></pre>
  
  <p>basically I thought this line would essentially say "if the field dbname is set and its value when trimming it is equal to something then do this, if not then do this" but instead when I added this line in the whole thing just broke and stopped displaying anything in the browser.</p>
  
  <p>incase you need it the rest of my file looks like this</p>
  
  <pre><code>function show_form($msg = '') {
  ?&gt;
  &lt;html&gt;
      &lt;body&gt;
          &lt;?php if (isset($msg) &amp;&amp; trim($msg) != '') { echo $msg; } ?&gt;
          &lt;P&gt; HI &lt;/P&gt;
          &lt;form action="hi.php" method="POST"&gt;
              &lt;p&gt;Your Database name and user: &lt;input type="text" name="dbname" /&gt;&lt;br /&gt;
              Your database password &lt;input type="text" name="dbpass" /&gt; &lt;br/&gt;
              Your DB_HOST (ip address) &lt;input type ="text" name = "dbhost" /&gt; &lt;br/&gt; 
              Your desired table prefix &lt;input type ="text" name = "prefix" /&gt; &lt;br /&gt;
              &lt;/p&gt;
  
              &lt;p&gt;&lt;input type="submit" value="Send it!"&gt;&lt;/p&gt;
          &lt;/form&gt;
  &lt;?php
          }
          ?&gt;
  &lt;?php
  function recurseRmdir($di) {
    $files = array_diff(scandir($di), array('.','..'));
    foreach ($files as $file) {
      (is_dir("$di/$file")) ? recurseRmdir("$di/$file") : unlink("$di/$file");
    }
    return rmdir($di);
  }
  ?&gt;
  &lt;?php
  function do_install() { 
      chdir(__DIR__);
      $dir = getcwd(); /** stores the directory that the php file is in as a variable */
      file_put_contents($dir . '/wordpress.zip', file_get_contents('http://wordpress.org/latest.zip'));
      $zip = new ZipArchive;
      $zip-&gt;open('wordpress.zip');
      $zip-&gt;extractTo($dir);
      $zip-&gt;close();
      unlink($dir . '/wordpress/wp-content/plugins/hello.php');
      recurseRmdir($dir . '/wordpress/wp-content/plugins/akismet');
      recurseRmdir($dir . '/wordpress/wp-content/themes/twentyfourteen');
      recurseRmdir($dir . '/wordpress/wp-content/themes/twentythirteen');
      recurseRmdir($dir . '/wordpress/wp-content/themes/twentytwelve');
      file_put_contents ($dir . '/wpbfboilerplate.zip', file_get_contents ('/home/wpbfboilerplate.zip'));
      $zip = new ZipArchive;
      $zip-&gt;open('wpbfboilerplate.zip');
      $zip-&gt;extractTo($dir);
      $zip-&gt;close();
      unlink($dir . '/wordpress.zip');
      unlink($dir . '/wpbfboilerplate.zip');
      rename($dir . '/wordpress/wp-config-sample.php', $dir . '/wordpress/wp-config.php');
      $contents = file_get_contents($dir . '/wordpress/wp-config.php');
      $new_contents = str_replace('database_name_here',$dbname, $contents);
      file_put_contents('wordpress/wp-config.php', $new_contents);
      $contents = file_get_contents($dir . '/wordpress/wp-config.php');
      $new_contents = str_replace('username_here', $dbname, $contents);
      file_put_contents('wordpress/wp-config.php', $new_contents);
      $contents = file_get_contents($dir . '/wordpress/wp-config.php');
      $new_contents = str_replace('localhost', $dbhost, $contents);
      file_put_contents('wordpress/wp-config.php', $new_contents);
      $contents = file_get_contents($dir . '/wordpress/wp-config.php');
      $new_contents = str_replace('password_here', $dbpass, $contents);
      file_put_contents('wordpress/wp-config.php', $new_contents);
      $contents = file_get_contents($dir . '/wordpress/wp-config.php');
      $new_contents = str_replace("\$table_prefix  = 'wp_';", "\$table_prefix  =" . "'" . $prefix . "'", $contents);
      file_put_contents('wordpress/wp-config.php', $new_contents);
      }
  ?&gt;
  </code></pre>