How to compare User Input to Custom WordPress Database Table
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
php mysql database wordpress
add a comment |
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
php mysql database wordpress
I have checked it with$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.
– Shahid Khattak
Nov 14 '18 at 6:45
add a comment |
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
php mysql database wordpress
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
php mysql database wordpress
php mysql database wordpress
asked Nov 14 '18 at 6:42
Shahid KhattakShahid Khattak
3010
3010
I have checked it with$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.
– Shahid Khattak
Nov 14 '18 at 6:45
add a comment |
I have checked it with$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.
– Shahid Khattak
Nov 14 '18 at 6:45
I have checked it with
$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.– Shahid Khattak
Nov 14 '18 at 6:45
I have checked it with
$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.– Shahid Khattak
Nov 14 '18 at 6:45
add a comment |
1 Answer
1
active
oldest
votes
There is a typo in the name for the column in filter. It should be auth_code and not auht_code;
$prepared_statement = $wpdb->prepare(
"SELECT auth_code FROM $table_name WHERE auth_code = %s", $prod_auth );
$values = $wpdb->get_col( $prepared_statement );
I have corrected the typo, but still not working.
– Shahid Khattak
Nov 15 '18 at 16:52
Perhaps the value for$prod_authused in the where clause doesn't exist in the table. You can check to confirm if there is an error running the querywpdb->print_error()
– Oluwafemi Sule
Nov 15 '18 at 17:15
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53294451%2fhow-to-compare-user-input-to-custom-wordpress-database-table%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
There is a typo in the name for the column in filter. It should be auth_code and not auht_code;
$prepared_statement = $wpdb->prepare(
"SELECT auth_code FROM $table_name WHERE auth_code = %s", $prod_auth );
$values = $wpdb->get_col( $prepared_statement );
I have corrected the typo, but still not working.
– Shahid Khattak
Nov 15 '18 at 16:52
Perhaps the value for$prod_authused in the where clause doesn't exist in the table. You can check to confirm if there is an error running the querywpdb->print_error()
– Oluwafemi Sule
Nov 15 '18 at 17:15
add a comment |
There is a typo in the name for the column in filter. It should be auth_code and not auht_code;
$prepared_statement = $wpdb->prepare(
"SELECT auth_code FROM $table_name WHERE auth_code = %s", $prod_auth );
$values = $wpdb->get_col( $prepared_statement );
I have corrected the typo, but still not working.
– Shahid Khattak
Nov 15 '18 at 16:52
Perhaps the value for$prod_authused in the where clause doesn't exist in the table. You can check to confirm if there is an error running the querywpdb->print_error()
– Oluwafemi Sule
Nov 15 '18 at 17:15
add a comment |
There is a typo in the name for the column in filter. It should be auth_code and not auht_code;
$prepared_statement = $wpdb->prepare(
"SELECT auth_code FROM $table_name WHERE auth_code = %s", $prod_auth );
$values = $wpdb->get_col( $prepared_statement );
There is a typo in the name for the column in filter. It should be auth_code and not auht_code;
$prepared_statement = $wpdb->prepare(
"SELECT auth_code FROM $table_name WHERE auth_code = %s", $prod_auth );
$values = $wpdb->get_col( $prepared_statement );
answered Nov 14 '18 at 7:13
Oluwafemi SuleOluwafemi Sule
12.3k1533
12.3k1533
I have corrected the typo, but still not working.
– Shahid Khattak
Nov 15 '18 at 16:52
Perhaps the value for$prod_authused in the where clause doesn't exist in the table. You can check to confirm if there is an error running the querywpdb->print_error()
– Oluwafemi Sule
Nov 15 '18 at 17:15
add a comment |
I have corrected the typo, but still not working.
– Shahid Khattak
Nov 15 '18 at 16:52
Perhaps the value for$prod_authused in the where clause doesn't exist in the table. You can check to confirm if there is an error running the querywpdb->print_error()
– Oluwafemi Sule
Nov 15 '18 at 17:15
I have corrected the typo, but still not working.
– Shahid Khattak
Nov 15 '18 at 16:52
I have corrected the typo, but still not working.
– Shahid Khattak
Nov 15 '18 at 16:52
Perhaps the value for
$prod_auth used in the where clause doesn't exist in the table. You can check to confirm if there is an error running the query wpdb->print_error()– Oluwafemi Sule
Nov 15 '18 at 17:15
Perhaps the value for
$prod_auth used in the where clause doesn't exist in the table. You can check to confirm if there is an error running the query wpdb->print_error()– Oluwafemi Sule
Nov 15 '18 at 17:15
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53294451%2fhow-to-compare-user-input-to-custom-wordpress-database-table%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
I have checked it with
$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.– Shahid Khattak
Nov 14 '18 at 6:45