So I got this far. I first connect to the database, validate the customer ID that is entered into the form, then do something with it. The problem is that I am getting a SQL error when entering letters into the form, saying “mysql_num_rows() expects parameter 1 to be resource, boolean”.
Also, I am embedding a shortcode into this function using the “do_shortcode(‘shortcode’)” function and it’s showing the name of the shortcode as text rather than actually populating the shortcode data.
function restrictForum(){
$db_name = 'dbname';
$con = mysql_connect("url","username","password");
mysql_select_db("$db_name")or die("cannot select DB");
$cust_id = mysql_real_escape_string($_GET['cid']);
$sql = "SELECT * FROM customer_data WHERE customer_number = $cust_id";
$result= mysql_query($sql);
if ( isset( $_GET['cid'] ) && !empty( $_GET['cid'] ) && mysql_num_rows($result) == 1) {
// cid (customer ID) is present, show the bbPress login form
echo do_shortcode('bbp-login');
} elseif ( $_GET['error'] == true ) {
// cid entered was not valid
echo 'The customer ID you entered is not valid.';
} else {
echo ('<form name="cust-form" id="cust-form" method="get">
<label for="cid">Enter Your Customer #</label><input name="cid" id="cid" type="text" maxlength="6" />
<input type="submit" value="Validate"');
// cid is absent so show the form to validate it
// do your custom form here that asks for the customer ID. Then if the customer ID
// is correct/valid reload this page like /login?cid=123456 which will show
// the bbPress login form.
}
}
add_shortcode('forum-login-restrict','restrictForum');