I'm trying to do a directory where u can add yourself by entering the code sms. After entering the correct code sms, it checks if code exist in the database, then remove entered code from DB and add data from form. Now I have a problem because I do not know how to prevent from adding data into the database, when the given code is incorrect. At the moment, it looks like this:
if ($sum != $val1+$val2) { //simple captcha
echo '<div id="message_position_capreg"><p class="error_form"><font color="red">Incorrect. Try again</font></p></div>';
}
else {
if ($_POST['code']){
$code=$_POST['code'];
global $wpdb;
$sql = $wpdb->prepare("SELECT id FROM code_sms WHERE code = %s", $cd);
$check_code = $wpdb->get_results($sql);
if ($check_code>0) {
$wpdb->delete( 'code_sms', array( 'code' => $code ) );
if ( isset( $_POST["submit_formm"] ) && $_POST["company_nip"] && $_POST["company_name"] != "" ){
$company_nip = strip_tags($_POST["company_nip"], "");
$company_name = strip_tags($_POST["company_name"], "");
$result = $wpdb->insert(
'test',
array(
'company_nip' => $company_nip, 'company_name' => $company_name)
);
if (!$result) {
echo '<div>
ERROR</div>';
}
else {
echo '<div>
Succes</div>';
}
}
}
}
}
EDIT: I editted my code, like @thephatp said, and it's now working :)