update not working using wpdb

Question

I am fetching the row value in the $specie variable, then in the form i am passing the id in the hidden field, but on updating it shows page not found error? what i am doing wrong??

<?php
global $wpdb;
$species = get_query_var( 'species' );
$specie = $wpdb->get_row( "SELECT * FROM wp_species WHERE name = '$species'" );
?>
  <section class="section-1">
<div class="container">
  <h3>Edit Species</h3>
  <hr>
  <div class="inquiry-form wow fadeInRight" data-wow-duration=".8s" data-wow-delay=".5s">
      <?php
        if(isset($_POST['submit'])) {
            $wpdb->update( 
                'wp_species', 
                array( 
                    'name' => $_POST['name'],   // string
                    'common_name' => $_POST['commonName'],  // string
                    'taxon_group' => $_POST['taxonGroup']   // string
                ), 
                array( 'id' => $_POST['id'] ), 
                array( 
                    '%s',   // value1
                    '%s',   // value2
                    '%s'    // value3
                ), 
                array( '%d' ) 
            );
        echo "<p class='alert alert-success'>Details updated!</p>";
        }
        ?>
    <form method="post" enctype="multipart/form-data">
      <div class="row justify-content-center align-items-center">
        <div class="col-md-10">
          <div class="form-group">
            <label for="species">Species Name</label>
              <input type="text" class="form-control" name="name" value="<?php echo $specie->name;?>" id="species">
              <input type="hidden" name="id" value="<?php echo $specie->id;?>">
          </div>
          <div class="form-group">
            <label for="cname">Common Name</label>
              <input type="text" class="form-control" name="commonName" value="<?php echo $specie->common_name;?>" id="cname">
          </div>
          <div class="form-group">
            <label for="tgroup">Taxon Group</label>
              <input type="text" class="form-control" name="taxonGroup" value="<?php echo $specie->taxon_group;?>" id="tgroup">
          </div>

          <div class="form-group">
            <button type="submit" name="submit" class="btn btn-block btn-red">Submit</button>
          </div>
        </div>
      </div>
    </form>
  </div>
</div>
0
Peace 3 years 2020-08-19T18:10:34-05:00 0 Answers 44 views 0

Leave an answer

Browse
Browse