title: Getting form data from PHP to MSSQL database
body: <p>I am creating a Database request form that will take requests from the requestor for a particular database on our network, run a randomizer script on it that will clear all user confidential information, and then send it to the requestor (support personnel or developer) for access and review.
  I am using PowerShell to generate a list of databases we have across all servers on the network and saving that information into a database which is then accessed by PHP.</p>
  <p>I have 2 pages setup as below.</p>
  <p>Index.php</p>
  <pre><code>&lt;!doctype HTML&gt;
  &lt;?php  
      $server=&quot;database server&quot;;
      $connectionInfo = array( &quot;Database&quot;=&gt;&quot;database&quot;, &quot;UID&quot;=&gt;&quot;user&quot;, &quot;PWD&quot;=&gt;&quot;password&quot;);
      $conn = sqlsrv_connect($server,$connectionInfo);
      if( $conn ) {
       echo &quot;Connection established.&lt;br /&gt;&quot;;
      }else{
       echo &quot;Connection could not be established.&lt;br /&gt;&quot;;
       die( print_r( sqlsrv_errors(), true));
      }
  ?&gt;
  &lt;html&gt;
  &lt;link rel='stylesheet' href='/styles.css' /&gt;
  &lt;head&gt;
  &lt;meta charset=&quot;utf-8&quot;&gt;
  &lt;title&gt;Client Database Request Portal&lt;/title&gt;
      &lt;header&gt; 
          &lt;h1 align=&quot;center&quot;&gt;Client Database Request Portal&lt;/h1&gt;
      &lt;/header&gt;
  &lt;link href=&quot;style.css&quot; rel=&quot;stylesheet&quot; type=&quot;text/css&quot;&gt;
  &lt;/head&gt;
  &lt;form action=&quot;request.php&quot; method=&quot;post&quot;&gt;
    &lt;div class=&quot;elem-group&quot;&gt;
      &lt;label for=&quot;name&quot;&gt;Name:&lt;/label&gt;
      &lt;input type=&quot;text&quot; id=&quot;name&quot; name=&quot;requestor&quot; placeholder=&quot;John Doe&quot; pattern=[A-Z\sa-z]{3,20} required&gt;
    &lt;/div&gt;
    &lt;div class=&quot;elem-group&quot;&gt;
      &lt;label for=&quot;email&quot;&gt;E-mail:&lt;/label&gt;
      &lt;input type=&quot;email&quot; id=&quot;email&quot; name=&quot;requestor_email&quot; placeholder=&quot;john.doe@email.com&quot; required&gt;
    &lt;/div&gt;
    &lt;div class=&quot;elem-group&quot;&gt;
      &lt;label for=&quot;database-selection&quot;&gt;Database:&lt;/label&gt;
          &lt;select&gt;
            &lt;option&gt;Select a Database&lt;/option&gt;
              &lt;?php 
              $sql = &quot;SELECT DatabaseName, DatabaseServer FROM databases&quot;;
              $result = sqlsrv_query($conn, $sql);
              while ($row = sqlsrv_fetch_array($result)) {
              echo '&lt;option&gt;'.$row['DatabaseName'].'&lt;/option&gt;';
              }   
              ?&gt;
            &lt;/select&gt;
      &lt;/div&gt;
    &lt;div class=&quot;elem-group&quot;&gt;
      &lt;label for=&quot;randomize-database&quot;&gt;Randomize Database?&lt;/label&gt;
      &lt;input type=&quot;radio&quot; id=&quot;Yes&quot; name=&quot;Yes&quot; Value=&quot;Yes&quot; checked&gt;Yes&lt;/input&gt;
      &lt;input type=&quot;radio&quot; id=&quot;No&quot; name=&quot;No&quot; Value=&quot;No&quot; disabled&gt;No&lt;/input&gt;
    &lt;/div&gt;
    &lt;button type=&quot;submit&quot;&gt;Submit&lt;/button&gt;
   &lt;/form&gt;
   &lt;?php sqlsrv_close( $conn );?&gt;
  &lt;form action=&quot;request.php&quot; method=&quot;POST&quot;&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  <p>Request.php</p>
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;?php  
          $server=&quot;database server&quot;;
          $connectionInfo = array( &quot;Database&quot;=&gt;&quot;database&quot;, &quot;UID&quot;=&gt;&quot;user&quot;, &quot;PWD&quot;=&gt;&quot;password&quot;);
          $conn = sqlsrv_connect($server,$connectionInfo);
          if( $conn ) {
           echo &quot;Connection established.&lt;br /&gt;&quot;;
          }else{
           echo &quot;Connection could not be established.&lt;br /&gt;&quot;;
           die( print_r( sqlsrv_errors(), true));
          }
  ?&gt;
  &lt;html&gt;
    
  &lt;head&gt;
      &lt;title&gt;Request page&lt;/title&gt;
  &lt;/head&gt;
    
  &lt;body&gt;
      &lt;center&gt;
          &lt;?php $timestamp = date('Y-m-d H:i:s');
          $name =  $_REQUEST['requestor'];
          $email = $_REQUEST['requestor_email'];
          $database =  $_REQUEST['DatabaseName'];
          //$randomize = $_REQUEST['randomize-database'];
          
          $sql = &quot;INSERT INTO dbo.requests VALUES ('$name', 
              '$email','$database', $timestamp)&quot;;
            
          if(sqlsrv_query($conn, $sql)){
              echo &quot;&lt;h3&gt;data stored in a database successfully.&quot; 
                  . &quot; Please browse your localhost php my admin&quot; 
                  . &quot; to view the updated data&lt;/h3&gt;&quot;; 
    
              echo nl2br(&quot;\$name\n $email\n &quot;
                  . &quot;$database\n $randomize&quot;);
          } else{
              echo &quot;ERROR: Hush! Sorry $sql. &quot; 
                  . sqlsrv_error($conn);
          }
            
          // Close connection
         sqlsrv_close($conn);?&gt;
      &lt;/center&gt;
  &lt;/body&gt;
    
  &lt;/html&gt;
  </code></pre>
  <p>I need help setting or forwarding those variables from index.php to request.php because right now it shows success but nothing is written in the database, as well as figuring out a way to download  or backup the selected database run a query on it and upload it to dropbox (which can be done via API)</p>