title: My current insert statement is not working
body: <p>Im creating a gift form for users to input their values. However the forms used to be working but suddenly, after a day, it goes straight into invalid. I am not sure where it goes wrong. Please help me out. Here are my codes. I have already review it and it seems fine to me. This problem kept on occuring and I cant pinpoint whats the mistake. I think it is something to do with the dates. In the database, I have put the datatype as DATE.</p>
  <p><strong>CreateGift.cshtml</strong></p>
  <pre><code>@*Create Gift Page*@
  @model SignUp3.Models.Gift;
  @section MoreScripts {
  &lt;script src=&quot;~/lib/moment/moment.min.js&quot;&gt;&lt;/script&gt;
  &lt;link href=&quot;~/lib/dtpicker/css/tempusdominus-bootstrap-4.min.css&quot; rel=&quot;stylesheet&quot; /&gt;
  &lt;script src=&quot;~/lib/dtpicker/js/tempusdominus-bootstrap-4.min.js&quot;&gt;&lt;/script&gt;
  &lt;link href=&quot;~/lib/font-awesome/css/font-awesome.min.css&quot; rel=&quot;stylesheet&quot; /&gt;
  &lt;script src=&quot;~/lib/jquery-validate/jquery.validate.min.js&quot;&gt;&lt;/script&gt;
  &lt;script src=&quot;~/lib/jquery-validation-unobtrusive/jquery.validate.unobtrusive.min.js&quot;&gt;&lt;/script&gt;
  
      }
      &lt;!DOCTYPE html&gt;
      &lt;head&gt;
        &lt;meta charset=&quot;UTF-8&quot;&gt;
             &lt;link rel=&quot;stylesheet&quot; href=&quot;~/lib/styles/createform.css&quot;&gt;
     &lt;/head&gt;
     &lt;body&gt;
         &lt;div class=&quot;center&quot;&gt;
                  &lt;form id=&quot;createuser&quot; asp-controller=&quot;Gift&quot; asp-action=&quot;CreateGift&quot;
                           method=&quot;post&quot;&gt;
                    &lt;h3&gt;Create Gift&lt;/h3&gt;
                    &lt;div class=&quot;form-group row&quot;&gt;
              &lt;label class=&quot;control-label col-sm-3&quot; asp-for=&quot;description&quot;&gt;Description:&lt;span style=&quot;color:red;&quot;&gt;*&lt;/span&gt; &lt;/label&gt;
              &lt;div class=&quot;col-sm-5&quot;&gt;
                  &lt;input asp-for=&quot;description&quot; placeholder=&quot;Full Name&quot; class=&quot;form-control&quot; /&gt;
              &lt;/div&gt;
              &lt;div class=&quot;col-sm-3&quot;&gt;
                  &lt;span asp-validation-for=&quot;description&quot; class=&quot;text-danger&quot;&gt;&lt;/span&gt;
              &lt;/div&gt;
          &lt;/div&gt;
          &lt;div class=&quot;form-group row&quot;&gt;
              &lt;label class=&quot;control-label col-sm-3&quot; asp-for=&quot;vouchercode&quot;&gt;Voucher Code:&lt;span style=&quot;color:red;&quot;&gt;*&lt;/span&gt; &lt;/label&gt;
              &lt;div class=&quot;col-sm-5&quot;&gt;
                  &lt;input asp-for=&quot;vouchercode&quot; placeholder=&quot;Voucher Code&quot; class=&quot;form-control&quot; /&gt;
              &lt;/div&gt;
              &lt;div class=&quot;col-sm-3&quot;&gt;
                  &lt;span asp-validation-for=&quot;vouchercode&quot; class=&quot;text-danger&quot;&gt;&lt;/span&gt;
              &lt;/div&gt;
          &lt;/div&gt;
          &lt;div class=&quot;form-group row&quot;&gt;
              &lt;label class=&quot;control-label col-sm-3&quot; asp-for=&quot;amount&quot;&gt;Voucher Amount:&lt;span style=&quot;color:red;&quot;&gt;*&lt;/span&gt; &lt;/label&gt;
              &lt;div class=&quot;col-sm-5&quot;&gt;
                  &lt;input asp-for=&quot;amount&quot; placeholder=&quot;Amount&quot; class=&quot;form-control&quot; /&gt;
              &lt;/div&gt;
              &lt;div class=&quot;col-sm-3&quot;&gt;
                  &lt;span asp-validation-for=&quot;amount&quot; class=&quot;text-danger&quot;&gt;&lt;/span&gt;
              &lt;/div&gt;
          &lt;/div&gt;
          &lt;div class=&quot;form-group row&quot;&gt;
              &lt;label class=&quot;control-label col-sm-3&quot; asp-for=&quot;quantity&quot;&gt;Quantity:&lt;span style=&quot;color:red;&quot;&gt;*&lt;/span&gt; &lt;/label&gt;
              &lt;div class=&quot;col-sm-5&quot;&gt;
                  &lt;input asp-for=&quot;quantity&quot; placeholder=&quot;Quantity&quot; class=&quot;form-control&quot; /&gt;
              &lt;/div&gt;
              &lt;div class=&quot;col-sm-3&quot;&gt;
                  &lt;span asp-validation-for=&quot;quantity&quot; class=&quot;text-danger&quot;&gt;&lt;/span&gt;
              &lt;/div&gt;
          &lt;/div&gt;
          &lt;div class=&quot;form-group row&quot;&gt;
              &lt;label class=&quot;control-label col-sm-3&quot; asp-for=&quot;activation_date&quot;&gt;Activation Date:&lt;span style=&quot;color:red;&quot;&gt;*&lt;/span&gt;&lt;/label&gt;
              &lt;div class=&quot;col-sm-5&quot;&gt;
                  &lt;input asp-for=&quot;activation_date&quot; asp-format=&quot;{0:yyyy-MM-dd}&quot;
                         class=&quot;form-control&quot; placeholder=&quot;YYYY-MM-DD&quot; /&gt;
              &lt;/div&gt;
              &lt;div class=&quot;col-sm-3&quot;&gt;
                  &lt;span asp-validation-for=&quot;activation_date&quot; class=&quot;text-danger&quot;&gt;&lt;/span&gt;
  
              &lt;/div&gt;
          &lt;/div&gt;
  
          &lt;div class=&quot;form-group row&quot;&gt;
              &lt;label class=&quot;control-label col-sm-3&quot; asp-for=&quot;expiry&quot;&gt;Expiry Date:&lt;span style=&quot;color:red;&quot;&gt;*&lt;/span&gt;&lt;/label&gt;
              &lt;div class=&quot;col-sm-5&quot;&gt;
                  &lt;input asp-for=&quot;expiry&quot; asp-format=&quot;{0:yyyy-MM-dd}&quot;
                         class=&quot;form-control&quot; placeholder=&quot;YYYY-MM-DD&quot; /&gt;
              &lt;/div&gt;
              &lt;div class=&quot;col-sm-3&quot;&gt;
                  &lt;span asp-validation-for=&quot;expiry&quot; class=&quot;text-danger&quot;&gt;&lt;/span&gt;
  
              &lt;/div&gt;
          &lt;/div&gt;
          &lt;div class=&quot;form-group row&quot;&gt;
              &lt;div class=&quot;offset-sm-3 col-sm-6&quot;&gt;
                  &lt;input type=&quot;submit&quot; value=&quot;Submit&quot; class=&quot;btn btn-primary&quot; /&gt;
              &lt;/div&gt;
          &lt;/div&gt;
  
          @if (ViewData[&quot;Message&quot;] != null)
          {
              &lt;div class=&quot;form-group row&quot;&gt;
                  &lt;div class=&quot;offset-sm-2 col-sm-6&quot;&gt;
                      &lt;div class=&quot;alert alert-@ViewData[&quot;MsgType&quot;]&quot;&gt;
                          @Html.Raw(ViewData[&quot;Message&quot;])
                      &lt;/div&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
          }
      &lt;/form&gt;
  
  &lt;/div&gt;
  </code></pre>
  
  <p><strong>GiftController.cs</strong></p>
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Data;
  using System.Linq;
  using System.Threading.Tasks;
  using Microsoft.AspNetCore.Authorization;
  using Microsoft.AspNetCore.Mvc;
  using SignUp3.Models;
  
  namespace SignUp3.Controllers
  {
    public class GiftController : Controller
    {
      [Authorize]
      public IActionResult CreateGift()
      {
          return View();
      }
  
  
      [HttpPost]
      public IActionResult CreateGift(Gift gift)
      {
          // TODO: L09 Task 5 - Write secure code to insert Users into database
          if (!ModelState.IsValid)
          {
              ViewData[&quot;Message&quot;] = &quot;Invalid Input&quot;;
              ViewData[&quot;MsgType&quot;] = &quot;warning&quot;;
              return View(&quot;CreateGift&quot;);
          }
          else
          {
  
               
              string sql = @&quot;INSERT INTO GiftVoucher (description,amount,vouchercode,quantity,activation_date,expiry)
              VALUES('{0}',{1},'{2}',{3},'{4}','{5}')&quot;;
  
              if (DBUtl.ExecSQL(sql, gift.description,gift.amount, gift.vouchercode,gift.quantity,gift.activation_date,gift.expiry) == 1)
              {
                  TempData[&quot;Message&quot;] = &quot;Gift Sucessfully Added.&quot;;
                  TempData[&quot;MsgType&quot;] = &quot;success&quot;;
                  return RedirectToAction(&quot;ViewGift&quot;);
              }
              else
              {
                  ViewData[&quot;Message&quot;] = &quot;Invalid&quot;;
                  ViewData[&quot;MsgType&quot;] = &quot;danger&quot;;
                  return View(&quot;CreateGift&quot;);
              }
          }
      }
  </code></pre>