I have created a plugin which creates a table in the database, I have inserted some values in that table as well. The table has only two columns which are ID and auth_code, the ID column is the primary key and autoincrement, so the only column to be considered is the auth_code column. The table creation and data insertion are working perfectly. I have added a shortcode which I want to use for the user to input a code (on the front end) in a single field and my plugin will compare it with the auth_code field in the custom table and return TRUE or False. The auth_code column is having values which are all unique, so there should be only one match or no match. My shortcode code is here
<?php
add_shortcode( 'prod_auth', 'product_auth_shortcode' );
function product_auth_shortcode(){
global $wpdb;
$table_name = $wpdb->prefix.'wpa_product_auth';
if(isset($_POST['submit'])){
$prod_auth = $_POST['auth_code'];
$check = $wpdb->get_col("SELECT * FROM $table_name WHERE auht_code = '$prod_auth'");
if($check->num_rows == 1){
echo "<script>alert('Auth')</script>";
}else{
echo "<script>alert('Not Auth')</script>";
}
}
?>
<form class="form-inline" method="post">
<div class="form-group mb-2">
<input type="text" readonly class="form-control-plaintext" value="Please
Enter Your Unique Code">
</div>
<div class="form-group mx-sm-3 mb-2">
<label for="UniqueCode" class="sr-only">Enter Your Unique Code</label>
<input type="text" class="form-control" id="inputPassword2" placeholder="" name="auth_code">
</div>
<button type="submit" class="btn btn-primary mb-2">Authenticate</button>
</form>
<?php
}
I have added this shortcode to one of my pages, the form is showing up there, but not returning any results. Any Help in this regard will be appreciated. Thanks
$wpdb->get_results()and the query$wpdb->get_results("SELECT auth_code FROM $table_name WHERE auht_code = '$prod_auth'");as well but not working.