title: Using one submit button to Update database and Send email?
body: <p>I am using one submit button to update data in a database and send an email. However the data is not being saved to the database. The code looks like:</p>
  
  <pre><code>&lt;?php
      if(isset($_POST['order_status']))
      {
      $dbhost = 'localhost';
      $dbuser = 'root';
      $dbpass = '';
      $conn = mysql_connect($dbhost, $dbuser, $dbpass);
      if(! $conn )
      {
      die('Could not connect: ' . mysql_error());
      }
  
      $orderno =$_POST['order_no'][$i];
      $status =$_POST['order_status'][$i];
      print_r($_POST['order_no']);
      $sql = 'UPDATE Orders SET status="' . $_POST['order_status'] . '" WHERE   Orderno="' .    $_POST['order_no'] . '"';
  
      mysql_select_db('PurchaseOrders');
      $retval = mysql_query( $sql, $conn );
      if(! $retval )
      {
      die('Could not update data: ' . mysql_error());
      }
      echo "Updated data successfully\n";
      mysql_close($conn);
      }
  ?&gt;
  &lt;?php
      if(isset($_POST['order_selected']))
      {
      $keys = array_keys($_POST['order_selected']);
  
      foreach($keys as $key)
      {
          $to = $_POST['order_requested_by'][$key];
          $subject = "Order Form Approval";
          $message = "Your purchase order number: " . " " . $_POST['order_no'][$key] ."    ". "is" ." ". $_POST['order_status'][$key] ;
          $headers = "From: noreply@somewhere.com";
          $sent = mail($to, $subject, $message, $headers) ;
          if($sent)
          {header( 'Location: http://localhost/test/../' ) ; }
          else
          {print "We encountered an error sending your mail"; }
      }
  }
  ?&gt;
  </code></pre>
  
  <p>In my form the input fields look like this:</p>
  
  <pre><code> echo '&lt;td&gt;&lt;input type="text" readonly=true name="order_supplier['.$i.']" value="' .    $row['Supplier'] . '"/&gt;&lt;/td&gt;';
      echo '&lt;td&gt;&lt;input type="text" readonly=true name="order_total_price['.$i.']" value="' . $row['totalprice'] . '"/&gt;&lt;/td&gt;';
      echo '&lt;td&gt;&lt;input type="text" readonly=true name="order_requested_by['.$i.']" value="' . $row['requestedby'] . '"/&gt;&lt;/td&gt;';
      echo '&lt;td&gt;';
      echo '&lt;select name="order_status['.$i.']" id="id" onchange="showUser(this.value)" &gt;';
      echo '&lt;option value = "Pending"   name="order_status['.$i.']" class = "pending"' . ($row['status'] == 'Pending' ? ' selected=selected' : '') . '&gt;Pending&lt;/option&gt;';
  echo '&lt;option value = "Approved"  name="order_status['.$i.']" class = "approved"' .     ($row['status'] == 'Approved' ? ' selected=selected' : '') . '&gt;Approved&lt;/option&gt;';
      echo '&lt;option value = "Disapproved" name="order_status['.$i.']" class     ="disapproved"' . ($row['status'] == 'Disapproved' ? ' selected=selected' : '') . '&gt;Disapproved&lt;/option&gt;';
      echo '&lt;/select&gt;';
  </code></pre>
  
  <p>I really do not know why this is breaking. When i click submit a message appears that the data has successfully been entered into the database. However no data is entered. Many Thanks</p>