title: Using PHP, Unable to post inside of function call line, able to post outside of function call line
body: <p>I'm using PHP, HTML, and MySQL to create a web page that lets users create text posts.  I would like to avoid js and ajax for now.</p>
  <p>When calling the function &quot;post&quot; from <strong>(post.php)</strong> the system is unable to complete the post.  Removing the function line in <strong>(includes/post.inc.php)</strong> lets the user post correctly.  I want to have the function line so I can reference multiple methods on this file.  What am I messing up for the call of this function?</p>
  <p><strong>Here is the relevant information from post.php</strong></p>
  <pre><code>    &lt;?php
          require 'includes/dbh.inc.php';
          require 'includes/post.inc.php';
          session_start();
          date_default_timezone_set('America/Chicago');
          .
          . 
          echo '
              &lt;form action=&quot;'.post($conn).'&quot; method=&quot;post&quot;&gt;
                  &lt;label for=&quot;text&quot;&gt;New Post&lt;/label&gt;
                  &lt;input type=&quot;text&quot; name=&quot;Text&quot; placeholder=&quot;Write your post here&quot;&gt;
                  &lt;input type=&quot;hidden&quot; name=&quot;Date&quot; value=&quot;'.date(&quot;Y-m-d H:i:s&quot;).'&quot;&gt;
                  &lt;br&gt;
                  &lt;button type=&quot;submit&quot; name=&quot;postSubmit&quot;&gt;Post&lt;/button&gt;
              &lt;/form&gt;
          ';
      ?&gt;
  </code></pre>
  <p>Then here is the post function from <strong>includes/post.inc.php</strong></p>
  <pre><code>&lt;?php
  
  function post($conn) {  // deleting this line allows my code to run correctly
      session_start();
      if (isset($_POST['postSubmit'])) {
          require 'dbh.inc.php';
          $UserID = $_SESSION['UserID'];
          $Date = $_POST['Date'];
          $Text = $_POST['Text'];
          $SectionID = 1;
          // make a random value for $postID and then see if it exists in the DB
          $PostIDLength = 11;
          $PostIDString = &quot;123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ&quot;;
          $PostIDDuplicate = true;
          while ($PostIDDuplicate = true) {
              $PostID = substr(str_shuffle($PostIDString), 0, $PostIDLength); //shuffle String, start with 0, 11 characters long
              $PostIDSQL = &quot;SELECT PostID FROM PostTable WHERE PostID = ?&quot;;
              $PostIDStmt = mysqli_stmt_init($conn);
              if (!mysqli_stmt_prepare($PostIDStmt, $PostIDSQL)) {
                  exit();
              }
              else {
                  mysqli_stmt_bind_param($PostIDStmt, &quot;s&quot;, $PostID);
                  mysqli_stmt_execute($PostIDStmt);
                  $PostIDResult = mysqli_stmt_get_result($PostIDStmt);
                  $PostIDResultCheck = mysqli_num_rows($PostIDResult);
                  if ($PostIDResultCheck &lt;= 0) {
                      $PostIDDuplicate = false;
                      break;
                  }
                  else {
                      // repeat until you have a unique ID
                  }
              }               
          }
          $PostSQL = &quot;INSERT INTO PostTable (PostID, UserID, SectionID, Date, Text) VALUES (?, ?, ?, ?, ?)&quot;;
          $PostSTMT = mysqli_stmt_init($conn);
          if (!mysqli_stmt_prepare($PostSTMT, $PostSQL)) {
              echo 'Error2';
          }
          else {
              mysqli_stmt_bind_param($PostSTMT, &quot;ssiss&quot;, $PostID, $UserID, $SectionID, $Date, $Text);
              mysqli_stmt_execute($PostSTMT);
          }
          header('Location: ../home');
          exit();
      }
      else {
          header(&quot;Location: ../home.php?error&quot;);
          exit();
      }
  }   
  </code></pre>