Why can't the edit-modal fetch the data(of the selected row) from my database?



.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















So this is my brand.php file
And it portrays the edit part of the brand
so in this part we can probably see how the thing will look like



 <!-- edit brand -->
<div class="modal fade" id="editBrandModel" tabindex="-1" role="dialog">
<div class="modal-dialog">
<div class="modal-content">

<form class="form-horizontal" id="editBrandForm" action="php_action/editBrand.php" method="POST">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
<h4 class="modal-title"><i class="fa fa-edit"></i> Edit Brand</h4>
</div>
<div class="modal-body">

<div id="edit-brand-messages"></div>

<div class="modal-loading div-hide" style="width:50px; margin:auto;padding-top:50px; padding-bottom:50px;">
<i class="fa fa-spinner fa-pulse fa-3x fa-fw"></i>
<span class="sr-only">Loading...</span>
</div>

<div class="edit-brand-result">
<div class="form-group">
<label for="editBrandName" class="col-sm-3 control-label">Brand Name: </label>
<label class="col-sm-1 control-label">: </label>
<div class="col-sm-8">
<input type="text" class="form-control" id="editBrandName" placeholder="Brand Name" name="editBrandName" autocomplete="off">
</div>
</div> <!-- /form-group-->
<div class="form-group">
<label for="editBrandStatus" class="col-sm-3 control-label">Status: </label>
<label class="col-sm-1 control-label">: </label>
<div class="col-sm-8">
<select class="form-control" id="editBrandStatus" name="editBrandStatus">
<option value="">~~SELECT~~</option>
<option value="1">Available</option>
<option value="2">Not Available</option>
</select>
</div>
</div> <!-- /form-group-->
</div>
<!-- /edit brand result -->

</div> <!-- /modal-body -->

<div class="modal-footer editBrandFooter">
<button type="button" class="btn btn-default" data-dismiss="modal"> <i class="glyphicon glyphicon-remove-sign"></i> Close</button>

<button type="submit" class="btn btn-success" id="editBrandBtn" data-loading-text="Loading..." autocomplete="off"> <i class="glyphicon glyphicon-ok-sign"></i> Save Changes</button>
</div>
<!-- /modal-footer -->
</form>
<!-- /.form -->
</div>
<!-- /modal-content -->
</div>
<!-- /modal-dailog -->
</div>
<!-- / add modal -->
<!-- /edit brand -->

> --this one is the end part


And this is the fetching part, wherein once you click the button from the row(example row 1), a modal(Edit Modal will likely appear), but the thing is, once the modal appear, the data that is supposed to be fetched from the row is not on that modal ;-;



 <?php 

require_once '../../includes/connection.php';

$brandId = $_POST['brandId'];

$sql = "SELECT brand_id, brand_name, brand_active, brand_status FROM brands WHERE brand_id = $brandId";
$result = $connect->query($sql);

if($result->num_rows > 0)
$row = $result->fetch_array();
// if num_rows

$connect->close();

echo json_encode($row);
?>


Now the JScript part
This part is the filler part(like getting the data and now portraying the data and filling the input boxes etc..)



function editBrands(brandId = null) 
if(brandId)
// remove hidden brand id text
$('#brandId').remove();

// remove the error
$('.text-danger').remove();
// remove the form-error
$('.form-group').removeClass('has-error').removeClass('has-success');

// modal loading
$('.modal-loading').removeClass('div-hide');
// modal result
$('.edit-brand-result').addClass('div-hide');
// modal footer
$('.editBrandFooter').addClass('div-hide');

$.ajax(
url: 'fetchSelectedBrand.php',
type: 'post',
data: brandId : brandId,
dataType: 'json',
success:function(response)
// modal loading
$('.modal-loading').addClass('div-hide');
// modal result
$('.edit-brand-result').removeClass('div-hide');
// modal footer
$('.editBrandFooter').removeClass('div-hide');

// setting the brand name value
$('#editBrandName').val(response.brand_name);
// setting the brand status value
$('#editBrandStatus').val(response.brand_active);
// brand id
$(".editBrandFooter").after('<input type="hidden" name="brandId" id="brandId" value="'+response.brand_id+'" />');

// update brand form
$('#editBrandForm').unbind('submit').bind('submit', function()

// remove the error text
$(".text-danger").remove();
// remove the form error
$('.form-group').removeClass('has-error').removeClass('has-success');

var brandName = $('#editBrandName').val();
var brandStatus = $('#editBrandStatus').val();

if(brandName == "")
$("#editBrandName").after('<p class="text-danger">Brand Name field is required</p>');
$('#editBrandName').closest('.form-group').addClass('has-error');
else
// remov error text field
$("#editBrandName").find('.text-danger').remove();
// success out for form
$("#editBrandName").closest('.form-group').addClass('has-success');


if(brandStatus == "")
$("#editBrandStatus").after('<p class="text-danger">Brand Name field is required</p>');

$('#editBrandStatus').closest('.form-group').addClass('has-error');
else
// remove error text field
$("#editBrandStatus").find('.text-danger').remove();
// success out for form
$("#editBrandStatus").closest('.form-group').addClass('has-success');


if(brandName && brandStatus)
var form = $(this);

// submit btn
$('#editBrandBtn').button('loading');

$.ajax(
url: form.attr('action'),
type: form.attr('method'),
data: form.serialize(),
dataType: 'json',
success:function(response)

if(response.success == true)
console.log(response);
// submit btn
$('#editBrandBtn').button('reset');

// reload the manage member table
manageBrandTable.ajax.reload(null, false);
// remove the error text
$(".text-danger").remove();
// remove the form error
$('.form-group').removeClass('has-error').removeClass('has-success');

$('#edit-brand-messages').html('<div class="alert alert-success">'+
'<button type="button" class="close" data-dismiss="alert">&times;</button>'+
'<strong><i class="glyphicon glyphicon-ok-sign"></i></strong> '+ response.messages +
'</div>');

$(".alert-success").delay(500).show(10, function()
$(this).delay(3000).hide(10, function()
$(this).remove();
);
); // /.alert
// /if

// /success
); // /ajax
// /if

return false;
); // /update brand form

// /success
); // ajax function

else
alert('error!! Refresh the page again');

// /edit brands function









share|improve this question




























    0















    So this is my brand.php file
    And it portrays the edit part of the brand
    so in this part we can probably see how the thing will look like



     <!-- edit brand -->
    <div class="modal fade" id="editBrandModel" tabindex="-1" role="dialog">
    <div class="modal-dialog">
    <div class="modal-content">

    <form class="form-horizontal" id="editBrandForm" action="php_action/editBrand.php" method="POST">
    <div class="modal-header">
    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
    <h4 class="modal-title"><i class="fa fa-edit"></i> Edit Brand</h4>
    </div>
    <div class="modal-body">

    <div id="edit-brand-messages"></div>

    <div class="modal-loading div-hide" style="width:50px; margin:auto;padding-top:50px; padding-bottom:50px;">
    <i class="fa fa-spinner fa-pulse fa-3x fa-fw"></i>
    <span class="sr-only">Loading...</span>
    </div>

    <div class="edit-brand-result">
    <div class="form-group">
    <label for="editBrandName" class="col-sm-3 control-label">Brand Name: </label>
    <label class="col-sm-1 control-label">: </label>
    <div class="col-sm-8">
    <input type="text" class="form-control" id="editBrandName" placeholder="Brand Name" name="editBrandName" autocomplete="off">
    </div>
    </div> <!-- /form-group-->
    <div class="form-group">
    <label for="editBrandStatus" class="col-sm-3 control-label">Status: </label>
    <label class="col-sm-1 control-label">: </label>
    <div class="col-sm-8">
    <select class="form-control" id="editBrandStatus" name="editBrandStatus">
    <option value="">~~SELECT~~</option>
    <option value="1">Available</option>
    <option value="2">Not Available</option>
    </select>
    </div>
    </div> <!-- /form-group-->
    </div>
    <!-- /edit brand result -->

    </div> <!-- /modal-body -->

    <div class="modal-footer editBrandFooter">
    <button type="button" class="btn btn-default" data-dismiss="modal"> <i class="glyphicon glyphicon-remove-sign"></i> Close</button>

    <button type="submit" class="btn btn-success" id="editBrandBtn" data-loading-text="Loading..." autocomplete="off"> <i class="glyphicon glyphicon-ok-sign"></i> Save Changes</button>
    </div>
    <!-- /modal-footer -->
    </form>
    <!-- /.form -->
    </div>
    <!-- /modal-content -->
    </div>
    <!-- /modal-dailog -->
    </div>
    <!-- / add modal -->
    <!-- /edit brand -->

    > --this one is the end part


    And this is the fetching part, wherein once you click the button from the row(example row 1), a modal(Edit Modal will likely appear), but the thing is, once the modal appear, the data that is supposed to be fetched from the row is not on that modal ;-;



     <?php 

    require_once '../../includes/connection.php';

    $brandId = $_POST['brandId'];

    $sql = "SELECT brand_id, brand_name, brand_active, brand_status FROM brands WHERE brand_id = $brandId";
    $result = $connect->query($sql);

    if($result->num_rows > 0)
    $row = $result->fetch_array();
    // if num_rows

    $connect->close();

    echo json_encode($row);
    ?>


    Now the JScript part
    This part is the filler part(like getting the data and now portraying the data and filling the input boxes etc..)



    function editBrands(brandId = null) 
    if(brandId)
    // remove hidden brand id text
    $('#brandId').remove();

    // remove the error
    $('.text-danger').remove();
    // remove the form-error
    $('.form-group').removeClass('has-error').removeClass('has-success');

    // modal loading
    $('.modal-loading').removeClass('div-hide');
    // modal result
    $('.edit-brand-result').addClass('div-hide');
    // modal footer
    $('.editBrandFooter').addClass('div-hide');

    $.ajax(
    url: 'fetchSelectedBrand.php',
    type: 'post',
    data: brandId : brandId,
    dataType: 'json',
    success:function(response)
    // modal loading
    $('.modal-loading').addClass('div-hide');
    // modal result
    $('.edit-brand-result').removeClass('div-hide');
    // modal footer
    $('.editBrandFooter').removeClass('div-hide');

    // setting the brand name value
    $('#editBrandName').val(response.brand_name);
    // setting the brand status value
    $('#editBrandStatus').val(response.brand_active);
    // brand id
    $(".editBrandFooter").after('<input type="hidden" name="brandId" id="brandId" value="'+response.brand_id+'" />');

    // update brand form
    $('#editBrandForm').unbind('submit').bind('submit', function()

    // remove the error text
    $(".text-danger").remove();
    // remove the form error
    $('.form-group').removeClass('has-error').removeClass('has-success');

    var brandName = $('#editBrandName').val();
    var brandStatus = $('#editBrandStatus').val();

    if(brandName == "")
    $("#editBrandName").after('<p class="text-danger">Brand Name field is required</p>');
    $('#editBrandName').closest('.form-group').addClass('has-error');
    else
    // remov error text field
    $("#editBrandName").find('.text-danger').remove();
    // success out for form
    $("#editBrandName").closest('.form-group').addClass('has-success');


    if(brandStatus == "")
    $("#editBrandStatus").after('<p class="text-danger">Brand Name field is required</p>');

    $('#editBrandStatus').closest('.form-group').addClass('has-error');
    else
    // remove error text field
    $("#editBrandStatus").find('.text-danger').remove();
    // success out for form
    $("#editBrandStatus").closest('.form-group').addClass('has-success');


    if(brandName && brandStatus)
    var form = $(this);

    // submit btn
    $('#editBrandBtn').button('loading');

    $.ajax(
    url: form.attr('action'),
    type: form.attr('method'),
    data: form.serialize(),
    dataType: 'json',
    success:function(response)

    if(response.success == true)
    console.log(response);
    // submit btn
    $('#editBrandBtn').button('reset');

    // reload the manage member table
    manageBrandTable.ajax.reload(null, false);
    // remove the error text
    $(".text-danger").remove();
    // remove the form error
    $('.form-group').removeClass('has-error').removeClass('has-success');

    $('#edit-brand-messages').html('<div class="alert alert-success">'+
    '<button type="button" class="close" data-dismiss="alert">&times;</button>'+
    '<strong><i class="glyphicon glyphicon-ok-sign"></i></strong> '+ response.messages +
    '</div>');

    $(".alert-success").delay(500).show(10, function()
    $(this).delay(3000).hide(10, function()
    $(this).remove();
    );
    ); // /.alert
    // /if

    // /success
    ); // /ajax
    // /if

    return false;
    ); // /update brand form

    // /success
    ); // ajax function

    else
    alert('error!! Refresh the page again');

    // /edit brands function









    share|improve this question
























      0












      0








      0








      So this is my brand.php file
      And it portrays the edit part of the brand
      so in this part we can probably see how the thing will look like



       <!-- edit brand -->
      <div class="modal fade" id="editBrandModel" tabindex="-1" role="dialog">
      <div class="modal-dialog">
      <div class="modal-content">

      <form class="form-horizontal" id="editBrandForm" action="php_action/editBrand.php" method="POST">
      <div class="modal-header">
      <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
      <h4 class="modal-title"><i class="fa fa-edit"></i> Edit Brand</h4>
      </div>
      <div class="modal-body">

      <div id="edit-brand-messages"></div>

      <div class="modal-loading div-hide" style="width:50px; margin:auto;padding-top:50px; padding-bottom:50px;">
      <i class="fa fa-spinner fa-pulse fa-3x fa-fw"></i>
      <span class="sr-only">Loading...</span>
      </div>

      <div class="edit-brand-result">
      <div class="form-group">
      <label for="editBrandName" class="col-sm-3 control-label">Brand Name: </label>
      <label class="col-sm-1 control-label">: </label>
      <div class="col-sm-8">
      <input type="text" class="form-control" id="editBrandName" placeholder="Brand Name" name="editBrandName" autocomplete="off">
      </div>
      </div> <!-- /form-group-->
      <div class="form-group">
      <label for="editBrandStatus" class="col-sm-3 control-label">Status: </label>
      <label class="col-sm-1 control-label">: </label>
      <div class="col-sm-8">
      <select class="form-control" id="editBrandStatus" name="editBrandStatus">
      <option value="">~~SELECT~~</option>
      <option value="1">Available</option>
      <option value="2">Not Available</option>
      </select>
      </div>
      </div> <!-- /form-group-->
      </div>
      <!-- /edit brand result -->

      </div> <!-- /modal-body -->

      <div class="modal-footer editBrandFooter">
      <button type="button" class="btn btn-default" data-dismiss="modal"> <i class="glyphicon glyphicon-remove-sign"></i> Close</button>

      <button type="submit" class="btn btn-success" id="editBrandBtn" data-loading-text="Loading..." autocomplete="off"> <i class="glyphicon glyphicon-ok-sign"></i> Save Changes</button>
      </div>
      <!-- /modal-footer -->
      </form>
      <!-- /.form -->
      </div>
      <!-- /modal-content -->
      </div>
      <!-- /modal-dailog -->
      </div>
      <!-- / add modal -->
      <!-- /edit brand -->

      > --this one is the end part


      And this is the fetching part, wherein once you click the button from the row(example row 1), a modal(Edit Modal will likely appear), but the thing is, once the modal appear, the data that is supposed to be fetched from the row is not on that modal ;-;



       <?php 

      require_once '../../includes/connection.php';

      $brandId = $_POST['brandId'];

      $sql = "SELECT brand_id, brand_name, brand_active, brand_status FROM brands WHERE brand_id = $brandId";
      $result = $connect->query($sql);

      if($result->num_rows > 0)
      $row = $result->fetch_array();
      // if num_rows

      $connect->close();

      echo json_encode($row);
      ?>


      Now the JScript part
      This part is the filler part(like getting the data and now portraying the data and filling the input boxes etc..)



      function editBrands(brandId = null) 
      if(brandId)
      // remove hidden brand id text
      $('#brandId').remove();

      // remove the error
      $('.text-danger').remove();
      // remove the form-error
      $('.form-group').removeClass('has-error').removeClass('has-success');

      // modal loading
      $('.modal-loading').removeClass('div-hide');
      // modal result
      $('.edit-brand-result').addClass('div-hide');
      // modal footer
      $('.editBrandFooter').addClass('div-hide');

      $.ajax(
      url: 'fetchSelectedBrand.php',
      type: 'post',
      data: brandId : brandId,
      dataType: 'json',
      success:function(response)
      // modal loading
      $('.modal-loading').addClass('div-hide');
      // modal result
      $('.edit-brand-result').removeClass('div-hide');
      // modal footer
      $('.editBrandFooter').removeClass('div-hide');

      // setting the brand name value
      $('#editBrandName').val(response.brand_name);
      // setting the brand status value
      $('#editBrandStatus').val(response.brand_active);
      // brand id
      $(".editBrandFooter").after('<input type="hidden" name="brandId" id="brandId" value="'+response.brand_id+'" />');

      // update brand form
      $('#editBrandForm').unbind('submit').bind('submit', function()

      // remove the error text
      $(".text-danger").remove();
      // remove the form error
      $('.form-group').removeClass('has-error').removeClass('has-success');

      var brandName = $('#editBrandName').val();
      var brandStatus = $('#editBrandStatus').val();

      if(brandName == "")
      $("#editBrandName").after('<p class="text-danger">Brand Name field is required</p>');
      $('#editBrandName').closest('.form-group').addClass('has-error');
      else
      // remov error text field
      $("#editBrandName").find('.text-danger').remove();
      // success out for form
      $("#editBrandName").closest('.form-group').addClass('has-success');


      if(brandStatus == "")
      $("#editBrandStatus").after('<p class="text-danger">Brand Name field is required</p>');

      $('#editBrandStatus').closest('.form-group').addClass('has-error');
      else
      // remove error text field
      $("#editBrandStatus").find('.text-danger').remove();
      // success out for form
      $("#editBrandStatus").closest('.form-group').addClass('has-success');


      if(brandName && brandStatus)
      var form = $(this);

      // submit btn
      $('#editBrandBtn').button('loading');

      $.ajax(
      url: form.attr('action'),
      type: form.attr('method'),
      data: form.serialize(),
      dataType: 'json',
      success:function(response)

      if(response.success == true)
      console.log(response);
      // submit btn
      $('#editBrandBtn').button('reset');

      // reload the manage member table
      manageBrandTable.ajax.reload(null, false);
      // remove the error text
      $(".text-danger").remove();
      // remove the form error
      $('.form-group').removeClass('has-error').removeClass('has-success');

      $('#edit-brand-messages').html('<div class="alert alert-success">'+
      '<button type="button" class="close" data-dismiss="alert">&times;</button>'+
      '<strong><i class="glyphicon glyphicon-ok-sign"></i></strong> '+ response.messages +
      '</div>');

      $(".alert-success").delay(500).show(10, function()
      $(this).delay(3000).hide(10, function()
      $(this).remove();
      );
      ); // /.alert
      // /if

      // /success
      ); // /ajax
      // /if

      return false;
      ); // /update brand form

      // /success
      ); // ajax function

      else
      alert('error!! Refresh the page again');

      // /edit brands function









      share|improve this question














      So this is my brand.php file
      And it portrays the edit part of the brand
      so in this part we can probably see how the thing will look like



       <!-- edit brand -->
      <div class="modal fade" id="editBrandModel" tabindex="-1" role="dialog">
      <div class="modal-dialog">
      <div class="modal-content">

      <form class="form-horizontal" id="editBrandForm" action="php_action/editBrand.php" method="POST">
      <div class="modal-header">
      <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
      <h4 class="modal-title"><i class="fa fa-edit"></i> Edit Brand</h4>
      </div>
      <div class="modal-body">

      <div id="edit-brand-messages"></div>

      <div class="modal-loading div-hide" style="width:50px; margin:auto;padding-top:50px; padding-bottom:50px;">
      <i class="fa fa-spinner fa-pulse fa-3x fa-fw"></i>
      <span class="sr-only">Loading...</span>
      </div>

      <div class="edit-brand-result">
      <div class="form-group">
      <label for="editBrandName" class="col-sm-3 control-label">Brand Name: </label>
      <label class="col-sm-1 control-label">: </label>
      <div class="col-sm-8">
      <input type="text" class="form-control" id="editBrandName" placeholder="Brand Name" name="editBrandName" autocomplete="off">
      </div>
      </div> <!-- /form-group-->
      <div class="form-group">
      <label for="editBrandStatus" class="col-sm-3 control-label">Status: </label>
      <label class="col-sm-1 control-label">: </label>
      <div class="col-sm-8">
      <select class="form-control" id="editBrandStatus" name="editBrandStatus">
      <option value="">~~SELECT~~</option>
      <option value="1">Available</option>
      <option value="2">Not Available</option>
      </select>
      </div>
      </div> <!-- /form-group-->
      </div>
      <!-- /edit brand result -->

      </div> <!-- /modal-body -->

      <div class="modal-footer editBrandFooter">
      <button type="button" class="btn btn-default" data-dismiss="modal"> <i class="glyphicon glyphicon-remove-sign"></i> Close</button>

      <button type="submit" class="btn btn-success" id="editBrandBtn" data-loading-text="Loading..." autocomplete="off"> <i class="glyphicon glyphicon-ok-sign"></i> Save Changes</button>
      </div>
      <!-- /modal-footer -->
      </form>
      <!-- /.form -->
      </div>
      <!-- /modal-content -->
      </div>
      <!-- /modal-dailog -->
      </div>
      <!-- / add modal -->
      <!-- /edit brand -->

      > --this one is the end part


      And this is the fetching part, wherein once you click the button from the row(example row 1), a modal(Edit Modal will likely appear), but the thing is, once the modal appear, the data that is supposed to be fetched from the row is not on that modal ;-;



       <?php 

      require_once '../../includes/connection.php';

      $brandId = $_POST['brandId'];

      $sql = "SELECT brand_id, brand_name, brand_active, brand_status FROM brands WHERE brand_id = $brandId";
      $result = $connect->query($sql);

      if($result->num_rows > 0)
      $row = $result->fetch_array();
      // if num_rows

      $connect->close();

      echo json_encode($row);
      ?>


      Now the JScript part
      This part is the filler part(like getting the data and now portraying the data and filling the input boxes etc..)



      function editBrands(brandId = null) 
      if(brandId)
      // remove hidden brand id text
      $('#brandId').remove();

      // remove the error
      $('.text-danger').remove();
      // remove the form-error
      $('.form-group').removeClass('has-error').removeClass('has-success');

      // modal loading
      $('.modal-loading').removeClass('div-hide');
      // modal result
      $('.edit-brand-result').addClass('div-hide');
      // modal footer
      $('.editBrandFooter').addClass('div-hide');

      $.ajax(
      url: 'fetchSelectedBrand.php',
      type: 'post',
      data: brandId : brandId,
      dataType: 'json',
      success:function(response)
      // modal loading
      $('.modal-loading').addClass('div-hide');
      // modal result
      $('.edit-brand-result').removeClass('div-hide');
      // modal footer
      $('.editBrandFooter').removeClass('div-hide');

      // setting the brand name value
      $('#editBrandName').val(response.brand_name);
      // setting the brand status value
      $('#editBrandStatus').val(response.brand_active);
      // brand id
      $(".editBrandFooter").after('<input type="hidden" name="brandId" id="brandId" value="'+response.brand_id+'" />');

      // update brand form
      $('#editBrandForm').unbind('submit').bind('submit', function()

      // remove the error text
      $(".text-danger").remove();
      // remove the form error
      $('.form-group').removeClass('has-error').removeClass('has-success');

      var brandName = $('#editBrandName').val();
      var brandStatus = $('#editBrandStatus').val();

      if(brandName == "")
      $("#editBrandName").after('<p class="text-danger">Brand Name field is required</p>');
      $('#editBrandName').closest('.form-group').addClass('has-error');
      else
      // remov error text field
      $("#editBrandName").find('.text-danger').remove();
      // success out for form
      $("#editBrandName").closest('.form-group').addClass('has-success');


      if(brandStatus == "")
      $("#editBrandStatus").after('<p class="text-danger">Brand Name field is required</p>');

      $('#editBrandStatus').closest('.form-group').addClass('has-error');
      else
      // remove error text field
      $("#editBrandStatus").find('.text-danger').remove();
      // success out for form
      $("#editBrandStatus").closest('.form-group').addClass('has-success');


      if(brandName && brandStatus)
      var form = $(this);

      // submit btn
      $('#editBrandBtn').button('loading');

      $.ajax(
      url: form.attr('action'),
      type: form.attr('method'),
      data: form.serialize(),
      dataType: 'json',
      success:function(response)

      if(response.success == true)
      console.log(response);
      // submit btn
      $('#editBrandBtn').button('reset');

      // reload the manage member table
      manageBrandTable.ajax.reload(null, false);
      // remove the error text
      $(".text-danger").remove();
      // remove the form error
      $('.form-group').removeClass('has-error').removeClass('has-success');

      $('#edit-brand-messages').html('<div class="alert alert-success">'+
      '<button type="button" class="close" data-dismiss="alert">&times;</button>'+
      '<strong><i class="glyphicon glyphicon-ok-sign"></i></strong> '+ response.messages +
      '</div>');

      $(".alert-success").delay(500).show(10, function()
      $(this).delay(3000).hide(10, function()
      $(this).remove();
      );
      ); // /.alert
      // /if

      // /success
      ); // /ajax
      // /if

      return false;
      ); // /update brand form

      // /success
      ); // ajax function

      else
      alert('error!! Refresh the page again');

      // /edit brands function






      javascript php mysqli crud edit






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 15 '18 at 7:56









      Mj DltMj Dlt

      11




      11






















          1 Answer
          1






          active

          oldest

          votes


















          0














          Can you check the Network tab to see the result from server? You can debug your app by seeing that result.



          By the way, there're two things that you may need to edit:



          1/ If brandId is interger, you need to get it from $_GET by intval($_POST['brandId']) to prevent SQL Injection.



          2/



          if($result->num_rows > 0) 
          $row = $result->fetch_array();

          else
          $row = array();



          your code need to return empty array if sql result is empty to avoid Undefined variable error.






          share|improve this answer























            Your Answer






            StackExchange.ifUsing("editor", function ()
            StackExchange.using("externalEditor", function ()
            StackExchange.using("snippets", function ()
            StackExchange.snippets.init();
            );
            );
            , "code-snippets");

            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "1"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













            draft saved

            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53314732%2fwhy-cant-the-edit-modal-fetch-the-dataof-the-selected-row-from-my-database%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            Can you check the Network tab to see the result from server? You can debug your app by seeing that result.



            By the way, there're two things that you may need to edit:



            1/ If brandId is interger, you need to get it from $_GET by intval($_POST['brandId']) to prevent SQL Injection.



            2/



            if($result->num_rows > 0) 
            $row = $result->fetch_array();

            else
            $row = array();



            your code need to return empty array if sql result is empty to avoid Undefined variable error.






            share|improve this answer



























              0














              Can you check the Network tab to see the result from server? You can debug your app by seeing that result.



              By the way, there're two things that you may need to edit:



              1/ If brandId is interger, you need to get it from $_GET by intval($_POST['brandId']) to prevent SQL Injection.



              2/



              if($result->num_rows > 0) 
              $row = $result->fetch_array();

              else
              $row = array();



              your code need to return empty array if sql result is empty to avoid Undefined variable error.






              share|improve this answer

























                0












                0








                0







                Can you check the Network tab to see the result from server? You can debug your app by seeing that result.



                By the way, there're two things that you may need to edit:



                1/ If brandId is interger, you need to get it from $_GET by intval($_POST['brandId']) to prevent SQL Injection.



                2/



                if($result->num_rows > 0) 
                $row = $result->fetch_array();

                else
                $row = array();



                your code need to return empty array if sql result is empty to avoid Undefined variable error.






                share|improve this answer













                Can you check the Network tab to see the result from server? You can debug your app by seeing that result.



                By the way, there're two things that you may need to edit:



                1/ If brandId is interger, you need to get it from $_GET by intval($_POST['brandId']) to prevent SQL Injection.



                2/



                if($result->num_rows > 0) 
                $row = $result->fetch_array();

                else
                $row = array();



                your code need to return empty array if sql result is empty to avoid Undefined variable error.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 15 '18 at 8:35









                Van ThoVan Tho

                846




                846





























                    draft saved

                    draft discarded
















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53314732%2fwhy-cant-the-edit-modal-fetch-the-dataof-the-selected-row-from-my-database%23new-answer', 'question_page');

                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    How to how show current date and time by default on contact form 7 in WordPress without taking input from user in datetimepicker

                    Syphilis

                    Darth Vader #20