jquery - Calling two php files on form submit -


i have coded form gets 2 kinds of values user, 1 promo details , other asks photo (the photo optional). need photo uploaded in folder , have slideshowed. question how send photo folder , insert promo details database , slideshow tool should use picks out random images on folder? here code form asks user input , photo:

<form action="insertpromo.php" method="post">             <div class="form-group">                 <label class="control-label col-sm-2" for="txtpromoname">promo title:</label>                     <div class="col-sm-10" id="divcmbservice"">                         <input type="text" class="form-control" name="txtpromoname" id="txtpromoname" placeholder="promo name">                     </div>             </div>              <div class="form-group">                 <label class="control-label col-sm-2" for="cmbservice">service discount:</label>                     <div class="col-sm-10">                                       <select id="cmbservice" name="cmbservice" class="form-control" onchange="showservice(this.value)">                                     <option value="0">- select 1 -</option>                         <?php                                                                    $dbhost = "localhost";                             $dbuser = "mdchadmin";                             $dbpass = "123456";                             $dbname = "mdch_new";                              $conn = new mysqli($dbhost, $dbuser, $dbpass, $dbname);                                 if ($conn->connect_error) {                                     die("connection failed: " . $conn->connect_error);                                 }                                  $sql = "select service_id, service_name services";                                 $result = $conn->query($sql);                                 if ($result->num_rows > 0) {                                     while($row = $result->fetch_assoc()) {                                     echo "<option value=\"{$row['service_id']}\">{$row['service_name']}</option>";                                                 }                                 }                                                                        $conn->close();                                                                      ?>                             </select>                 </div>             </div>               <div class="form-group">                 <label class="control-label col-sm-2" for="txtpresyo">input promo cost:</label>                     <div class="col-sm-10" id="divcmbservice"">                         <input type="text" class="form-control" name="txtpresyo" id="txtpresyo" placeholder="0.00">                     </div>             </div>                   <div class="form-group">                       <label class="control-label col-sm-2" for="txtvalidfrom">valid from:</label>                         <div class="col-sm-10">                             <input class="form-control login-field" type="date" id="txtvalidfrom" name="txtvalidfrom" size=17>                         </div>                 </div>                 <div class="form-group">                       <label class="control-label col-sm-2" for="txtvaliduntil">valid until:</label>                         <div class="col-sm-10">                             <input class="form-control login-field" type="date" id="txtvaliduntil" name="txtvaliduntil" size=17>                         </div>                 </div>                         <?php echo "<br>";echo "<br>";echo "<br>";echo "<br>";?>                 <div class="form-group">                 <label class="control-label col-sm-2" for="txtservicename"> promo photo upload:</label>                     <div class="col-sm-10" id="divcmbservice"">                         <input name="promo" type="file" enctype = "multipart/form-data">                                             </div>             </div>              <div class="form-group">                     <div class="col-sm-offset-2 col-sm-10">                     <input type="submit" class="btn btn-default" value="add promo">                 </div>             </div>                 </form>      

here code file sends data database:

<?php error_reporting(e_error); include('session.php'); if (false==$_session['isadmin']){      header("location:index.php");     die();       } ?> <html lang="en">  <body> <div id="wrapper">             <?php             include('nav_admin.php');             ?>         <div id="page-wrapper">              <div class="container-fluid">                     <div class="row">                         <div class="col-lg-12">                         <h1 class="page-header">insert new promo</h1>                     </div>                     <div class="col-xs-6">                     <div class="container">                         <?php                                              try{                                             $dbhost = "localhost";                                             $dbuser = "mdchadmin";                                             $dbpass = "123456";                                             $dbname = "mdch_new";                                              $conn = new mysqli($dbhost, $dbuser, $dbpass, $dbname);                                             if ($conn->connect_error) {                                                 die("connection failed: " . $conn->connect_error);                                             }                                               // escape user inputs 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 promos (promo_name, service_id, discounted_price, valid_from, valid_until) values ('$promotitle', $serviceid, $discountedcost, '$datefrom', '$dateuntil')";                                             if ($conn->query($sql) === true) {                                                 echo "promo ";echo $promotitle; echo " created. promo valid "; echo $datefrom; echo " until "; echo $dateuntil;                                              } else {                                                 echo "cannot insert promo. please fill of fields.";                                             }                                              // close connection                                             $conn->close();                                     }catch (exception $e) {                                             echo 'error: ' . $e->getmessage();                                         }                          ?>                                   <form enctype="multipart/form-data" action="addpromo.php" method="post">                                 <?php echo "<br>";echo "<br>";echo "<br>";?>                                                     <div class="form-group">                                         <div class="col-sm-offset-2 col-sm-10">                                         <input type="submit" class="btn btn-default" value="back add promo page">                                     </div>                                 </div>                       </div>                     </form>                     </div>                     </div>                     </div>             </div>         </div> </div>  </body> </html> 

i have googled how upload pic , works me, dont know how can photo upload , insertion of data db simultaneously.

<?php   include('insertpromo.php');//this writes db   include('upload.php'); //this uploads photo ?> 

then make form action="promoincluder.php" promo includer contains code above


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -