title: Save Inputs into database & class errors - building coupon system
body: <p>Okay, I'm building (trying) a coupon code system for my admin panel, what I want to achieve is allow admin to manually create coupons by setting its <strong>coupon_code</strong> and <strong>coupon_discount (1% TO 100%)</strong>. When he will submit, it will be stored in two different tables of two dbs. </p>
  
  <p>TABLE <strong>coupons:</strong></p>
  
  <ul>
  <li>coupon_id INT(10) NOT NULL AUTO INCREMENT - Primary key</li>
  <li>coupon_code VARCHAR(15) NOT NULL - unique</li>
  <li>discount DECIMAL(3,2)</li>
  <li>expire DATETIME  -NULL </li>
  <li>count  INT(10)  -NULL</li>
  </ul>
  
  <p><strong>I checked lots of examples on the net and this is my probably poorly written class:</strong>
      
  
  <pre><code>class ProductDiscount {
  
  static public function validate($coupon_code);
  
  private $_coupon_code;     // string
  private $_coupon_discount; // integer??
  private $_expire;   // null cause unlimited
  private $_count;    // null
  
  private function __construct();    //for this line I got an error
  public function getCouponCode();      // return string
  public function getCouponDiscount();  // return 
  public function getCount();     // returns null unlimited
  public function getExpireDate();// null
  
  public function useDiscount();      // apply this discount now
  
  public function useAllDiscount();   // invalidate this discount for future use
  </code></pre>
  
  <p><strong>COUPONS.PHP - new coupon creation</strong></p>
  
  <p>On the admin side, I am totally lost about how to pass the coupon_code and coupon_discount to the database...How to utilize the functions that I wrote in the class...This is what I did:</p>
  
  <pre><code>&lt;?php
  
  if($_SERVER['REQUEST_METHOD'] == 'POST') {
  $coupon_code = $_POST['coupon_code'];
  $coupon_discount = $_POST['coupon_discount'];
  
  //insert into db for admin
  $connect = new mysqli("localhost","-----","-------","--------");
  $stmt = $connect-&gt;prepare("INSERT INTO `coupons` (`coupon_code`, `coupon_discount`) VALUES (?,?)");
  $stmt-&gt;bind_param('si', $coupon_code, $coupon_discount);
  $stmt-&gt;execute();
  $connect-&gt;close();
  }  
  ?&gt;
  </code></pre>
  
  <p><strong>I'm getting undefined index errors for both the coupon_code and coupon_discount..</strong></p>
  
  <p>If I require_once my class file here, I'm getting <strong>Non-abstract method ProductDiscount::create() must contain body error.</strong></p>
  
  <pre><code>&lt;form class="form-horizontal" role="form" action="createcoupon.php"&gt;
  &lt;div class="form-group"&gt;
      &lt;label class="col-sm-2 control-label"&gt;Coupon Code&lt;/label&gt;
      &lt;div class="col-sm-2"&gt;
        &lt;input type="text" class="form-control" name="coupon_code" id="couponCode" placeholder="e.g SAVE10"&gt;
      &lt;/div&gt;
      &lt;/div&gt;
  
  &lt;div class="form-group"&gt;
      &lt;label class="col-sm-2 control-label"&gt;Coupon Discount&lt;/label&gt;
      &lt;div class="col-sm-2"&gt;
        &lt;input type="number" class="form-control" name="coupon_discount" id="couponDiscount" placeholder="e.g 10 for 10%"&gt;
  &lt;/div&gt;
  &lt;/div&gt;
  
  &lt;div class="form-group"&gt;
  &lt;div class="col-sm-offset-2 col-sm-3"&gt;
    &lt;input type="submit" style="background-color:#7575DD; padding:0 !important; color:white;" name="create_coupon" value="Create Coupon" class="btn btn-default"/&gt;
  &lt;/div&gt;
  &lt;/div&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p><strong>Here is my createcoupon.php</strong>:</p>
  
  <pre><code>&lt;?php
  //Connect to the 1st db
      $coupon_code = $_POST['coupon-code'];
      $coupon_discount = $_POST['coupon-discount'];
  //the prepared stmt to insert into db1
  
  //Connect to the 2nd tb
      $coupon_code = $_POST['coupon-code'];
      $coupon_discount = $_POST['coupon-discount'];
  //prepared stmt to insert into db2
  header("location: http://example.com/admin/coupons");
  ?&gt;
  </code></pre>
  
  <p>It's 4am and been hours that I'm trying to learn these.</p>
  
  <p>So <em>my question is:</em> <strong>"How can I save the necessary form data to the table in the correct way and save the coupon into the table?"</strong></p>
  
  <p>(<strong>edited and specified my current problem only, can you reopen?</strong>)</p>
  
  <p>(<strong>commented the long/unnecessary parts to clarify</strong>)</p>
  
  <p>Thank you so much for your time!</p>