title: Calling two php files on form submit
body: <p>I have coded a form that gets 2 kinds of values from the user, one for promo details and the other asks for a photo (the photo is optional). I need to get the photo to be uploaded in a folder and have it slideshowed. My question is how do I send the photo to the folder and insert the promo details to the database and what slideshow tool should I use that just picks out random images on a folder?  here is my code for the form that asks the user input and photo: </p>
  
  <pre><code>&lt;FORM action="insertPromo.php" method="post"&gt;
              &lt;div class="form-group"&gt;
                  &lt;label class="control-label col-sm-2" for="txtPromoName"&gt;Promo Title:&lt;/label&gt;
                      &lt;div class="col-sm-10" id="divCmbService""&gt;
                          &lt;input type="text" class="form-control" name="txtPromoName" id="txtPromoName" placeholder="Promo Name"&gt;
                      &lt;/div&gt;
              &lt;/div&gt;
  
              &lt;div class="form-group"&gt;
                  &lt;label class="control-label col-sm-2" for="cmbService"&gt;Service to discount:&lt;/label&gt;
                      &lt;div class="col-sm-10"&gt;          
                              &lt;select id="cmbService" name="cmbService" class="form-control" onchange="showService(this.value)"&gt;
                                      &lt;option value="0"&gt;- Select One -&lt;/option&gt;
                          &lt;?php                                       
                              $dbHost = "localhost";
                              $dbUser = "mdchadmin";
                              $dbPass = "123456";
                              $dbName = "mdch_new";
  
                              $conn = new mysqli($dbHost, $dbUser, $dbPass, $dbName);
                                  if ($conn-&gt;connect_error) {
                                      die("Connection failed: " . $conn-&gt;connect_error);
                                  } 
                                  $sql = "SELECT service_id, service_name FROM services";
                                  $result = $conn-&gt;query($sql);
                                  if ($result-&gt;num_rows &gt; 0) {
                                      while($row = $result-&gt;fetch_assoc()) {
                                      echo "&lt;option value=\"{$row['service_id']}\"&gt;{$row['service_name']}&lt;/option&gt;";
                                                  }
                                  }                                       
                                  $conn-&gt;close();                                         
                              ?&gt;
                              &lt;/select&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
  
  
              &lt;div class="form-group"&gt;
                  &lt;label class="control-label col-sm-2" for="txtPresyo"&gt;Input Promo Cost:&lt;/label&gt;
                      &lt;div class="col-sm-10" id="divCmbService""&gt;
                          &lt;input type="text" class="form-control" name="txtPresyo" id="txtPresyo" placeholder="0.00"&gt;
                      &lt;/div&gt;
              &lt;/div&gt;
  
  
                  &lt;div class="form-group"&gt;
                        &lt;label class="control-label col-sm-2" for="txtValidFrom"&gt;Valid From:&lt;/label&gt;
                          &lt;div class="col-sm-10"&gt;
                              &lt;input class="form-control login-field" type="date" id="txtValidFrom" name="txtValidFrom" size=17&gt;
                          &lt;/div&gt;
                  &lt;/div&gt;
                  &lt;div class="form-group"&gt;
                        &lt;label class="control-label col-sm-2" for="txtValidUntil"&gt;Valid Until:&lt;/label&gt;
                          &lt;div class="col-sm-10"&gt;
                              &lt;input class="form-control login-field" type="date" id="txtValidUntil" name="txtValidUntil" size=17&gt;
                          &lt;/div&gt;
                  &lt;/div&gt;
                          &lt;?php echo "&lt;br&gt;";echo "&lt;br&gt;";echo "&lt;br&gt;";echo "&lt;br&gt;";?&gt;
                  &lt;div class="form-group"&gt;
                  &lt;label class="control-label col-sm-2" for="txtServiceName"&gt; Promo photo upload:&lt;/label&gt;
                      &lt;div class="col-sm-10" id="divCmbService""&gt;
                          &lt;INPUT NAME="promo" TYPE="file" enctype = "multipart/form-data"&gt;                        
                      &lt;/div&gt;
              &lt;/div&gt;
  
              &lt;div class="form-group"&gt;    
                  &lt;div class="col-sm-offset-2 col-sm-10"&gt;
                      &lt;INPUT TYPE="submit" class="btn btn-default" VALUE="Add Promo"&gt;
                  &lt;/div&gt;
              &lt;/div&gt;  
  
  
              &lt;/FORM&gt;     
  </code></pre>
  
  <p>Here is my code for the file that sends the data to the database:</p>
  
  <pre><code>&lt;?php
  error_reporting(E_ERROR);
  include('session.php');
  if (false==$_SESSION['isAdmin']){ 
      header("Location:index.php");
      die();      
  }
  ?&gt;
  &lt;html lang="en"&gt;
  
  &lt;body&gt;
  &lt;div id="wrapper"&gt;
              &lt;?php
              include('nav_admin.php');
              ?&gt;
          &lt;div id="page-wrapper"&gt; 
              &lt;div class="container-fluid"&gt;
                      &lt;div class="row"&gt;
                          &lt;div class="col-lg-12"&gt;
                          &lt;h1 class="page-header"&gt;Insert a new Promo&lt;/h1&gt;
                      &lt;/div&gt;
                      &lt;div class="col-xs-6"&gt;
                      &lt;div class="container"&gt;
                          &lt;?php           
  
  
                                  try{
                                              $dbHost = "localhost";
                                              $dbUser = "mdchadmin";
                                              $dbPass = "123456";
                                              $dbName = "mdch_new";
  
                                              $conn = new mysqli($dbHost, $dbUser, $dbPass, $dbName);
                                              if ($conn-&gt;connect_error) {
                                                  die("Connection failed: " . $conn-&gt;connect_error);
                                              } 
  
                                              // Escape user inputs for security
                                              $promoTitle= mysqli_real_escape_string($conn, $_POST['txtPromoName']);
                                              $serviceID = $_POST['cmbService'];
                                              $discountedCost = mysqli_real_escape_string($conn, $_POST['txtPresyo']);
                                                  date_default_timezone_set('Asia/Taipei');
                                                  $validFrom = $_POST['txtValidFrom'];
                                                  $validUntil = $_POST['txtValidUntil'];
                                                  $dateFrom = date('Y-m-d',strtotime($validFrom));
                                                  $dateUntil= date('Y-m-d',strtotime($validUntil));
                                              //$total_payment = mysqli_real_escape_string($conn, $_POST['txtTotalPayment']);
  
                                              // attempt insert query execution
                                              $sql = "INSERT INTO PROMOS (PROMO_NAME, SERVICE_ID, DISCOUNTED_PRICE, VALID_FROM, VALID_UNTIL) VALUES ('$promoTitle', $serviceID, $discountedCost, '$dateFrom', '$dateUntil')";
                                              if ($conn-&gt;query($sql) === TRUE) {
                                                  echo "Promo ";ECHO $promoTitle; echo " created. The promo is valid from "; echo $dateFrom; echo " until "; echo $dateUntil;
  
                                              } else {
                                                  echo "Cannot insert the promo. Please fill up all of the fields.";
                                              }
  
                                              // close connection
                                              $conn-&gt;close();
  
  
  
  
                                  }catch (Exception $e) {
                                              echo 'Error: ' . $e-&gt;getMessage();
                                          }
  
                          ?&gt;  
                                  &lt;FORM ENCTYPE="multipart/form-data" action="addPromo.php" method="post"&gt;
                                  &lt;?php echo "&lt;br&gt;";echo "&lt;br&gt;";echo "&lt;br&gt;";?&gt;                    
                                  &lt;div class="form-group"&gt;    
                                      &lt;div class="col-sm-offset-2 col-sm-10"&gt;
                                          &lt;INPUT TYPE="submit" class="btn btn-default" VALUE="Back to Add Promo Page"&gt;
                                      &lt;/div&gt;
                                  &lt;/div&gt;  
                      &lt;/div&gt;
                      &lt;/form&gt;
                      &lt;/div&gt;
                      &lt;/div&gt;
                      &lt;/div&gt;
              &lt;/div&gt;
          &lt;/div&gt;
  &lt;/div&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>I have googled how to upload the pic and it works for me, but I dont know how I can do the photo upload and the insertion of data to the db simultaneously.</p>