title: create save button in php file and execute some part of php code onclick it
body: <p>I have js file that takes user input and call php file on submit.
  The php file displays result of the entered data. I want to create "save button" to save these data in my database. "The save button should be in the php file"</p>
  
  <p>I try for the button in my php file:</p>
  
  <pre><code>&lt;?php
  
  echo "&lt;input type='button' value='Save Result'&gt; &lt;/p&gt;";  
  </code></pre>
  
  <p>I try this code in the same php file to save the result:</p>
  
  <pre><code>$serverName = "Alaa";
  $connectionInfo = array( "Database"=&gt;"i2b2blast", "UID"=&gt;"i2b2blast", "PWD"=&gt;"demouser");
  $conn = sqlsrv_connect( $serverName, $connectionInfo);
  
  if( $conn ) {
       echo "Connection established.&lt;br /&gt;";
  }else{
       echo "Connection could not be established.&lt;br /&gt;";
       die( print_r( sqlsrv_errors(), true));
  }
  
  $sql = "INSERT INTO BlastQueryDim (Query_ID, QuerySeq) VALUES ('Query 2', 'q')";
  
  $stmt = sqlsrv_query( $conn, $sql);
  if( $stmt === false ) {
       die( print_r( sqlsrv_errors(), true));
  }
  </code></pre>
  
  <p>I want when I click the button to perform the saving code.</p>
  
  <p>What I try and done successfully is:
  creating a test button in js file and call php file onclick it. In this case, the result successfully saved in my database but, I want the save button to be in the php file.</p>
  
  <p>Hope you getting my point.
  Thanks a lot.</p>
  
  <p>Edit 1:
  One possible solution is to call another php file from my current php one. I don't like this because I should post a lot of parameters.
  Anyway, in the first php file:</p>
  
  <pre><code>echo "&lt;form action='saveResult.php' method='post' name='Post'&gt;";
  echo "&lt;input name='Save' type='submit' value='Save Result'&gt; &lt;/p&gt;";  
  </code></pre>
  
  <p>in the second php:</p>
  
  <pre><code>&lt;?php
  if(isset($_POST['Save'])) // If the submit button was clicked
  {
  $serverName = "Alaa";
  $connectionInfo = array( "Database"=&gt;"i2b2blast", "UID"=&gt;"i2b2blast", "PWD"=&gt;"demouser");
  $conn = sqlsrv_connect( $serverName, $connectionInfo);
  if( $conn ) {
       echo "Connection established.&lt;br /&gt;";
  }else{
       echo "Connection could not be established.&lt;br /&gt;";
       die( print_r( sqlsrv_errors(), true));
  }
  $sql = "INSERT INTO BlastQueryDim (QueryID, QuerySeq) VALUES ('6', 'q')";
  $stmt = sqlsrv_query( $conn, $sql);
  if( $stmt === false ) {
       die( print_r( sqlsrv_errors(), true));
  }
  }
  echo "&lt;script&gt;alert('Saved');&lt;/script&gt;";
  </code></pre>
  
  <p>This work successfully but, it navigate the page to saveResult.php page.
  How can I execute the code of the second php "saveResult.php" in the background without redirect me?</p>