I’m trying to compare one input field i get from submit form, But even if number is correct it won’t echo success.
global $wpdb;
$name = $_POST['name'];
$phone = $_POST['surname'];
$kunde = $_POST['kunde'];
$login = $wpdb->get_results( "SELECT kunde FROM wp_kundenumber", ARRAY_N );
$kunde_string = end(explode(' ', $kunde));
if(in_array($kunde_string, $login)){
echo "succes";
}
else {
echo "failure";
}
EDIT: these are var dumps of variables:
for kunde_string
it says string(6) "100001"
and $login
is a big array array(9807) { [0]=> array(1) { [0]=> string(6) "100001" } [1]=> array(1) { [0]=> string(6) "100002" } [2]=> array(1) { [0]=> string(6) "100003" }...
you can use
array_map
php function instead of foreach loop, then usein_array
to find value..Check
in_array
withforeach
Try as follows