Is there anything wrong with this regex? [closed]

I’m trying to make a regex for National Identification Number for my country.
The format is CF or CM + last 2 digits of birth year + 6 digits + Letter + 2 digits + Letter.
An example is: CF95032102EA1H or CM95032102EA1H

This is my regex using php. When I run it, it returns Ivalid

$nin_regex = '/^(CF|CM)d{2}[0-9]{6}[A-Z]{1}[0-9]{2}[A-Z]{1}$/';

function validate_nin($nin) {
    global $nin_regex;
    return preg_match($nin_regex, $nin);
}

if (validate_nin('CF95032102EA1H')) {
    echo 'Valid NIN';
} else {
    echo 'Invalid NIN';
}

Laravel 2FA email

I am working on 2FA via email in my application , the problem I am facing is whenever I am logging in it automatically gets logged out and send me back to login page although it is sending me an email with correct user email through which I tried to login and it do not reaches to verify page .

here is my login_submit function

public function login_submit(Request $request)
{

    if(Auth::check()){
        return redirect()->route('admin.home')->with('success','Successfully logged in');
    }

    $request->validate([
        'email' => 'required|email',
        'password' => 'required|min:5',
    ]);

    $credentials = $request->only('email', 'password');
    
    
    if (Auth::attempt($credentials)) {
        
        // if(Auth::user()->role->name == 'Customer'){
        //   return redirect()->route('home')->with('success','Successfully logged in');    
        // }
        
        $user = auth()->user();
        
        $user->generateTwoFactorCode();
        $user->notify(new TwoFactorCode());
     
        
        if(auth()->check()) {
            return redirect()->route('verify.index')->with('success','Successfully logged in');
        }
        
    }else{
        
         return back()->with('error','These credentials do not match with our record');
        
    }

}

My User modal which includes both generate code and reset methods

<?php

namespace App;

use IlluminateContractsAuthMustVerifyEmail;
use IlluminateFoundationAuthUser as Authenticatable;
use IlluminateNotificationsNotifiable;
use IlluminateDatabaseEloquentSoftDeletes;
use AppReview;

class User extends Authenticatable
{
    use Notifiable;
    
    public $table = 'users';
    
     protected $dates = [
        'updated_at',
        'created_at',
        'deleted_at',
        'email_verified_at',
        'two_factor_expires_at',
    ];

    protected $guarded = [];

    /**
     * The attributes that should be hidden for arrays.
     *
     * @var array
     */
    protected $hidden = [
        'password', 'remember_token',
    ];

    /**
     * The attributes that should be cast to native types.
     *
     * @var array
     */
    protected $casts = [
        'email_verified_at' => 'datetime',
    ];
   
    
    
    /**
     * Generate 6 digits 2FA code for the User
     */
    public function generateTwoFactorCode()
    {
        $this->timestamps = false; //Dont update the 'updated_at' field yet
        
        $this->two_factor_code = rand(100000, 999999);
        $this->two_factor_expires_at = now()->addMinutes(10);
        $this->save();
    }

    /**
     * Reset the 2FA code generated earlier
     */
    public function resetTwoFactorCode()
    {
        $this->timestamps = false; //Dont update the 'updated_at' field yet
        
        $this->two_factor_code = null;
        $this->two_factor_expires_at = null;
        $this->save();
    }




}

Here is my verify routes along with middleware

 Route::get('verify/resend', 'AuthTwoFactorController@resend')->name('verify.resend');
 
 Route::resource('verify', 'AuthTwoFactorController')->only(['index', 'store']);

Route::prefix('admin')->middleware(['auth','twofactor','can:access_admin_panel'])->namespace('Admin')->name('admin.')->group(function () {

        Route::get('/home', 'DashboardController@index')->name('home');

}

and two_factor middleware is

<?php

namespace AppHttpMiddleware;

use Closure;

class TwoFactor
{
    /**
     * Handle an incoming request.
     *
     * @param  IlluminateHttpRequest  $request
     * @param  Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        $user = auth()->user();

        if(auth()->check() && $user->two_factor_code)
        {
            if($user->two_factor_expires_at<now()) //expired
            {
                $user->resetTwoFactorCode();
                auth()->logout();

                return redirect()->route('admin.login')->with('error','The two factor code has expired. Please login again.');
            }

           
            return redirect()->route('verify.index');
           
        }

        return $next($request);
    }
}

and below is my TwoFactorController :

<?php
        
        namespace AppHttpControllersAuth;
        
        use AppHttpControllersController;
        use AppNotificationsTwoFactorCode;
        use IlluminateHttpRequest;
        
        class TwoFactorController extends Controller
        {
            public function __construct()
            {
                $this->middleware('auth');
            }
        
            public function index() 
            {
               
                return view('auth.twoFactor');
            }
        
            public function store(Request $request)
            {
                $request->validate([
                    'two_factor_code' => 'integer|required',
                ]);
                
        
                $user = auth()->user();
        
                if($request->two_factor_code == $user->two_factor_code)
                {
                    $user->resetTwoFactorCode();
        
                    return redirect()->route('admin.home');
                }
        
                return back()->with('error' , 'The two factor code you have entered does not match');
            }
        
            public function resend()
            {
                $user = auth()->user();
                $user->generateTwoFactorCode();
                $user->notify(new TwoFactorCode());
        
                return back()->with('success','The two factor code has been sent again');
            }
        }
    
    }

Closure / Decorator in PHP?

I want to bind a function to another function to cache its results.
Unfortunately it’s not a class, hence I think I cannot use Closures.

I.e. like a decorator in Python.

I want to do this because I cannot modify the function with patching an API code.

So I have a function which gets called very often which always does one SQL query:

function api_func() {
    global $wpdb;
    // ... do a query without caching ...
    return $wpdb->get_col(...);
}

I want to surround this function by another function cache_func(), so that, whenever api_func() would be called, cache_func() gets called and can once cache the results.

Any ideas?

Thanks

i need to rank student based on their score (Subject Position) and also Overall Position

I have a project on student ranking. The sample school does three terminal exam in a year. I created a table where i stored all student test and exam according to their RegNo, year(session), semester, level and student arm(i.e A,B,C,D…) and all works perfectly.

The problem i’m facing now is the student overall position and subject position. For student subject position, I created a table called subject position where I want to have the position of students based on subject. And for the overall position I created a table that will automatically sum all the student result termly and rank them.

This is my table structure:

DROP TABLE IF EXISTS `subject_position`;

CREATE TABLE IF NOT EXISTS `subject_position` (

`id` int(11) NOT NULL AUTO_INCREMENT,

`regNo` varchar(50) NOT NULL,

`subjectid` varchar(50) NOT NULL,

`armsLevelId` varchar(50) NOT NULL,

`armsId` varchar(50) NOT NULL,

`semesterid` varchar(11) NOT NULL,

`yearid` varchar(50) NOT NULL,

`total` varchar(50) NOT NULL,

PRIMARY KEY (`id`)

) ENGINE=MyISAM AUTO_INCREMENT=73 DEFAULT CHARSET=latin1;

 

--

-- Dumping data for table `subject_position`

--

 

INSERT INTO `subject_position` (`id`, `regNo`, `subjectid`, `armsLevelId`, `armsId`, `semesterid`, `yearid`, `total`) VALUES

(1, '4663', '1', '1', '1', '1', '1', '72'),

(2, '6073', '1', '1', '1', '1', '1', '73'),

(3, '4663', '2', '1', '1', '1', '1', '47'),

(4, '6073', '2', '1', '1', '1', '1', '61'),

(5, '4663', '3', '1', '1', '1', '1', '82'),

(6, '6073', '3', '1', '1', '1', '1', '61'),

(7, '4663', '4', '1', '1', '1', '1', '99'),

(8, '6073', '4', '1', '1', '1', '1', '95'),

(9, '4663', '5', '1', '1', '1', '1', '70'),

(10, '6073', '5', '1', '1', '1', '1', '100'),

(11, '4663', '6', '1', '1', '1', '1', '69'),

(12, '6073', '6', '1', '1', '1', '1', '67'),

(13, '4663', '7', '1', '1', '1', '1', '77'),

(14, '6073', '7', '1', '1', '1', '1', '80'),

(15, '4663', '8', '1', '1', '1', '1', '58'),

(16, '6073', '8', '1', '1', '1', '1', '77'),

(17, '4663', '9', '1', '1', '1', '1', '96'),

(18, '6073', '9', '1', '1', '1', '1', '96'),

(19, '4663', '10', '1', '1', '1', '1', '78'),

(20, '6073', '10', '1', '1', '1', '1', '77'),

(21, '4663', '11', '1', '1', '1', '1', '48'),

(22, '6073', '11', '1', '1', '1', '1', '88'),

(23, '4663', '12', '1', '1', '1', '1', '69'),

(24, '6073', '12', '1', '1', '1', '1', '94'),

(25, '4663', '1', '1', '1', '2', '1', '28'),

(26, '6073', '1', '1', '1', '2', '1', '70'),

(27, '4663', '2', '1', '1', '2', '1', '68'),

(28, '6073', '2', '1', '1', '2', '1', '59'),

(29, '4663', '3', '1', '1', '2', '1', '68'),

(30, '6073', '3', '1', '1', '2', '1', '70'),

(31, '4663', '4', '1', '1', '2', '1', '81'),

(32, '6073', '4', '1', '1', '2', '1', '72'),

(33, '4663', '5', '1', '1', '2', '1', '84'),

(34, '6073', '5', '1', '1', '2', '1', '72'),

(35, '4663', '6', '1', '1', '2', '1', '58'),

(36, '6073', '6', '1', '1', '2', '1', '72'),

(37, '4663', '7', '1', '1', '2', '1', '71'),

(38, '6073', '7', '1', '1', '2', '1', '70'),

(39, '4663', '8', '1', '1', '2', '1', '48'),

(40, '6073', '8', '1', '1', '2', '1', '55'),

(41, '4663', '9', '1', '1', '2', '1', '66'),

(42, '6073', '9', '1', '1', '2', '1', '51'),

(43, '4663', '10', '1', '1', '2', '1', '37'),

(44, '6073', '10', '1', '1', '2', '1', '58'),

(45, '4663', '11', '1', '1', '2', '1', '57'),

(46, '6073', '11', '1', '1', '2', '1', '59'),

(47, '4663', '12', '1', '1', '2', '1', '67'),

(48, '6073', '12', '1', '1', '2', '1', '69'),

(49, '4663', '1', '1', '1', '3', '1', '94'),

(50, '6073', '1', '1', '1', '3', '1', '82'),

(51, '4663', '2', '1', '1', '3', '1', '69'),

(52, '6073', '2', '1', '1', '3', '1', '76'),

(53, '4663', '3', '1', '1', '3', '1', '63'),

(54, '6073', '3', '1', '1', '3', '1', '81'),

(55, '4663', '4', '1', '1', '3', '1', '81'),

(56, '6073', '4', '1', '1', '3', '1', '77'),

(57, '4663', '5', '1', '1', '3', '1', '72'),

(58, '6073', '5', '1', '1', '3', '1', '83'),

(59, '4663', '6', '1', '1', '3', '1', '78'),

(60, '6073', '6', '1', '1', '3', '1', '83'),

(61, '4663', '7', '1', '1', '3', '1', '77'),

(62, '6073', '7', '1', '1', '3', '1', '75'),

(63, '4663', '8', '1', '1', '3', '1', '74'),

(64, '6073', '8', '1', '1', '3', '1', '82'),

(65, '4663', '9', '1', '1', '3', '1', '56'),

(66, '6073', '9', '1', '1', '3', '1', '95'),

(67, '4663', '10', '1', '1', '3', '1', '87'),

(68, '6073', '10', '1', '1', '3', '1', '79'),

(69, '4663', '11', '1', '1', '3', '1', '70'),

(70, '6073', '11', '1', '1', '3', '1', '71'),

(71, '4663', '12', '1', '1', '3', '1', '82'),

(72, '6073', '12', '1', '1', '3', '1', '90');

COMMIT;

 

 

Table name: dummy (This table stores all students scores depending of RegNo, year(session), semester, level and student arm(i.e A,B,C,D…) respectively)

id regNo subjectid  armsLevelId  armsId  semesterid yearid  firstCA  seconCA  exam   total   grade    comment
1   4663       1                   1               1               1             1          9           8             55       72       B2         V.Good
2   6073       1                   1               1               1             1         10          8             55       73       B2          V.Good
3   4663      2                   1               1               1             1          6           8             33       47       D7          Pass
4   6073       2                  1               1               1             1          11          6             44       61       C4           Credit

 

Table name: subject_position (This table stores all students total scores termly depending of RegNo, year(session), semester, level and student arm(i.e A,B,C,D…) respectively)

id regNo subjectid  armsLevelId  armsId  semesterid yearid  total
1   4663       1                     1           1               1               1        72   
2   6073       1                     1           1               1               1        73  
3   4663      2                     1           1               1               1        47  
4   6073      2                     1           1               1               1         61  

..    ....          .                      .            .                .                .         ..

..    ....          .                      .            .                .                .         ..

..    ....          .                      .            .                .                .         ..

71  4663     12                   1            1               3               1         82 

72  6073     12                   1            1               3               1         90

 

Expected Output: for subject_position irrespective of the subject list

Note: Number of student here is two. we can have more than two(2) students

id regNo subjectid  armsLevelId  armsId  semesterid yearid  total  SubjectPos
1   4663       1              1                    1               1             1       72         2
2   6073       1              1                    1               1             1       73         1
3   4663      2              1                    1               1             1       47         2
4   6073      2              1                    1               1             1        61         1

..    ....          .                .                    .                .              .         ..          ..

..    ....          .                .                    .                .              .         ..          ..

..    ....          .                .                    .                .              .         ..          ..

71  4663     12             1                   1               3             1         82        2

72  6073     12             1                   1               3             1         90        1

 

My query

/Where subject id $sub is coming from/

$sql_subject = "select * from dummy where regid='$_GET[name]' and armsLevelId='$_SESSION[level_id]' and armsId='$_SESSION[arms]' and yearid='$_SESSION[session]' group by subjectid";

$result = mysqli_query($con,$sql_subject);

$datas_subject = array();

         while ($row_query=mysqli_fetch_array($result)){

                $RegNo=$row_query["regid"];

                $subject_id=$row_query["subjectid"];

                $level_id=$row_query["armsLevelId"];

                $arms=$row_query["armsId"];

                $semester=$row_query["semesterid"];

                $session=$row_query["yearid"];

                $fca=$row_query["firstCA"];

                $sca=$row_query["secondCA"];

                $exam=$row_query["exam"];

                $total =$row_query["total"];

                $grade =$row_query["grade"];

                $comment =$row_query["comment"];

 

$query_sub=mysqli_query($con,"select * from subject where id='".$subject_id."'");

               while ($row_sub=mysqli_fetch_array($query_sub)){

                           $r_sub = $row_sub["subject_name"];

                }

                         $datas_subject[] = $subject_id;

 }

 

for ($i=0; $i<count($datas_subject); $i++) {

       if(!empty($datas_subject[$i])){

           $sub = $datas_subject[$i];

       echo "Subject ID: ".$sub ."n";  // this printed all the list of subject ids

 

}else{

          //echo "Error Occured";

}

}


$sql = "SELECT * FROM `subject_position` where regNo='$RegNo'  and subjectid='$sub' and armsLevelId='$level_id' and armsId='$arms' and semesterid='$_SESSION[semester]' and yearid='$session' ORDER BY `total` DESC";

 

echo $sql . "n";    // This printed SELECT * FROM `subject_position` where regNo='4663' and subjectid='12' and armsLevelId='1' and armsId='1' and semesterid='1' and yearid='1' ORDER BY `total` DESC

//without looping through the subject Ids

 

$result = mysqli_query($con,$sql);

if( !$result ){

echo 'SQL Query Failed';

}else{

$rank = 0;

$last_score = false;

$rows = 0;

while( $row = mysqli_fetch_array( $result ) ){

$rows++;

     if( $last_score!= $row['total'] ){

           $last_score = $row['total'];

          $rank = $rows;

    }

          echo "rank ".$rank." is ".$row['regNo']." with point ".$row['total'] . "n";

     }

Best way to design a question based ordering system for a home service application

I am working on a home service application with laravel and react where users can submit orders for different services.
When a user is going to submit an order, the application is going to ask him/her some questions about the service details (like how many pipes are broken, what time does he/she like the service to be done and so on.)
So I need to create a services table:

+---------+--------------+------+-----+---------+----------------+
| Field   | Type         | Null | Key | Default | Extra          |
+---------+--------------+------+-----+---------+----------------+
| id      | int unsigned | NO   | PRI | NULL    | auto_increment |
| name    | varchar(200) | NO   |     | NULL    |                |
+---------+--------------+------+-----+---------+----------------+

And an orders table:

+------------+--------------+------+-----+---------+----------------+
| Field      | Type         | Null | Key | Default | Extra          |
+------------+--------------+------+-----+---------+----------------+
| id         | int unsigned | NO   | PRI | NULL    | auto_increment |
| service_id | int unsigned | NO   |     | NULL    |                |
| user_id    | int unsigned | NO   |     | NULL    |                |
| address_id | int unsigned | NO   |     | NULL    |                |
+------------+--------------+------+-----+---------+----------------+

Then I have to create a service_questions table:

+------------+--------------+------+-----+---------+----------------+
| Field      | Type         | Null | Key | Default | Extra          |
+------------+--------------+------+-----+---------+----------------+
| id         | int unsigned | NO   | PRI | NULL    | auto_increment |
| service_id | int unsigned | NO   |     | NULL    |                |
| type       | varchar(30)  | NO   |     | NULL    |                |
| name       | varchar(200) | NO   |     | NULL    |                |
+------------+--------------+------+-----+---------+----------------+

Questions may or may not have options. So the type attribute can have multiple values, like: single_select, multi_select, timestamp (for dates), text, file and … .
So I need a service_question_options table:

+-------------+--------------+------+-----+---------+----------------+
| Field       | Type         | Null | Key | Default | Extra          |
+-------------+--------------+------+-----+---------+----------------+
| uuid        | uuid         | NO   | PRI | NULL    | auto_increment |
| question_id | int unsigned | NO   |     | NULL    |                |
| content     | varchar(255) | NO   |     | NULL    |                |
+-------------+--------------+------+-----+---------+----------------+

I created a uuid field as identifier for this table so I would be able to store it in a varchar type field in the following table. For storing user’s answers to the questions, I create an order_answers table, like this:

+-------------+----------------+------+-----+---------+----------------+
| Field       | Type           | Null | Key | Default | Extra          |
+-------------+----------------+------+-----+---------+----------------+
| id          | int unsigned   | NO   | PRI | NULL    | auto_increment |
| order_id    | int unsigned   | NO   |     | NULL    |                |
| question_id | int unsigned   | NO   |     | NULL    |                |
| option      | varchar(255)   | YES  |     | NULL    |                |
+-------------+----------------+------+-----+---------+----------------+

Now that I explained all the tables, I need to mention the problems that I encountered. First, I receive user’s answers in an array like this:

[
    'first_question_id' => [
                               'an_option_id',
                               'another_option_id',
                           ],
    'second_question_id' => 'a_long_text',
    'third_question_id' => 'a_timestamp',
    ...
]

As you can see above, because there are different types of questions, the users answers may include question option uuid, a text, a timestamp and so on. So my first problem is that I need to validate all the question ids and option ids that user has sent, but I think that takes a lot of reading from database and may take a long time.

My second problem is the option attribute field type in order_answers table. What field type should it have, so I can store different types of data in it (uuid, text, datetime, urls for files and …)? Is it the best way or should I create different columns for different types of user answers? for example:

+-------------+----------------+------+-----+---------+----------------+
| Field       | Type           | Null | Key | Default | Extra          |
+-------------+----------------+------+-----+---------+----------------+
| id          | int unsigned   | NO   | PRI | NULL    | auto_increment |
| order_id    | int unsigned   | NO   |     | NULL    |                |
| question_id | int unsigned   | NO   |     | NULL    |                |
| option_id   | uuid           | YES  |     | NULL    |                |
| text        | text           | YES  |     | NULL    |                |
| datetime    | timestamp      | YES  |     | NULL    |                |
+-------------+----------------+------+-----+---------+----------------+

But, in this way, I will have lots of null cells in the table.
My third question is how should I read user orders from database, so I do not have to make lots of joins? Should I create a view?
Actually, a solution came to my mind that I’m not sure of. Lets assume we create the order_answers table like this:

+-------------+----------------+------+-----+---------+----------------+
| Field       | Type           | Null | Key | Default | Extra          |
+-------------+----------------+------+-----+---------+----------------+
| id          | int unsigned   | NO   | PRI | NULL    | auto_increment |
| order_id    | int unsigned   | NO   |     | NULL    |                |
| question    | varchar(200)   | NO   |     | NULL    |                |
| option      | varchar(255)   | YES  |     | NULL    |                |
+---------+---------------+----+-----+---------+-----------------------+

Then I receive questions and user answers content and not uuid or id. So I will not need to validate them and When reading from database, there is no need for any joins. Is it a good solution?
What is your best design for an application like this?

PHP code not connecting HTML to MYsql database

hey there im new to php ……so i wanted to make a program in which my html form inputs are stored in the data base I followed a youtube tutorial to do this this is the link to it enter link description hereand heres the code i have written for the php file `<?php

$firstname = $_POST ['firstname'] ;
$email = $_POST ['email'];
$admin = $_POST ['admin'];
$school = $_POST ['school'];
$gender = $_POST ['gender'] ;

//DATABASE CONECTION
$conn = new mysqli('localhost', 'root', '', 'register');
if ($conn-> connect_error){
die ('connection error    :  ' . $conn-> connect_error);
}else{
$stmt = $conn->prepare("INSERT INTO register(firstname, email, admin, gender)
values(?, ?, ?, ?, ?)");
$stmt-> bind_param("ssiss", $firstname, $email, $admin, $gender);
$stmt-> execute();
echo"Registration succesfull";
$stmt-> close();
$conn-> close();
}`

and here is my database
enter image description here
and my html program
enter image description here
but when i run it the html form runs fine but the php program is just displayed on the screen without any output pls help me thanks

Getting menu value from MySQL

I added user register & login system into my website with PHP jQuery and MySQL. I want if the user logged in, at the main page menu change the login buttons value to the user’s name from MySQL.
I tried some sources from the internet but it didn’t work

by the way here’s the project : https://zafernci.xyz/uploadd/

1

My Menu:

    <a class="active" href="#">Home</a>
    <a href="#">Contact</a> 
    <a href="#">Products</a> 
    <a id="sign-up" href="#" onclick="SignUp()">Sign Up</a> 
       <?php if(isset($_SESSION["username"])): ?>
    <a href="logout.php">Logout  ///.$_SESSION["username"]. I tried this code but that too didn't work//// </a>
       <?php else: ?>
    <a id="log-in" href="#" onclick="LogIn()">Log In</a>
       <?php endif; ?> 
       </div>  

The Login System with MySQL:

if(isset($_POST["username"]) && isset($_POST["password"]))
{
 $username = mysqli_real_escape_string($connect, $_POST["username"]);
 $password = md5(mysqli_real_escape_string($connect, $_POST["password"]));
 $sql = "SELECT * FROM users WHERE username = '".$username."' AND Password = '".$password."'";
 $result = mysqli_query($connect, $sql);
 $num_row = mysqli_num_rows($result);
 if($num_row > 0)
 {
  $data = mysqli_fetch_array($result);
  $_SESSION["username"] = $data["username"];
  echo $data["username"];
 }
}

Why would wp_mail think it’s succeeding, but not actually send mail?

I am using the wp_mail function within WordPress, but it only works sometimes. When I look at the error log, it says that mail is succeeding. This function is also being used for another email being sent – but that one works (at least sometimes, anyway).

if ( wp_mail( $emailTo, $subject, $body, $headers ) ) {
    error_log('mail success');
} else {
    error_log('mail fail');
}

What am I missing?

Dynamically generated PDFs not showing in certain browser

I use Ezpdf to generate invoices in pdf format. Last year everything was fine. Nothing has changed from the ezpdf code. Pdfs showed up on PC and Macs with no problem. This year, on certain browsers, a white page is shown instead of a pdf. To show how picky this is. On two macs (safari and Google) pdfs are generated perfectly. On another Mac the pdfs only show in Firefox. On certain Pcs they only show in Firefox but with misaligned margins at the top of page. I was wondering is anyone had come across something similar. Thank you.

Restrict live an input field comparing it to another field

I have a php page and these two inputs fields. My goal is to check if the second input is equal to first input (live) and make an error msg. The code i have so far is this:

<div class="input-group date" id="timepicker1"  
                                                                
    data-target-input="nearest">
    <input type="text" 

    class="form-control datetimepicker-input"
    data-target="#timepicker1"

    name="FirstDate" id="FirstDate"  />

</div>
<div class="input-group date" id="timepicker2"  
                                                                
    data-target-input="nearest">
    <input type="text" onclick="CheckForErrors()"

    class="form-control datetimepicker-input"
    data-target="#timepicker2"

    name="SecondDate" id="SecondDate"  />

</div>

In the end of the php i have a Javascript checking:

<script type="text/javascript">
    function CheckForErrors() {
      // Check if First Time is equal with second Time
      if (FirstDate == SecondDate) {
        alert("Error MSG!");
      }
      return false;
    }
</script>

Its not working, as u understand. Any help ?
PS. I’m a begginer so please be patient 😀

Twilio Reject Call and Send to Voicemail

I have a simple call structure folder with PHP and XML on my server. To handle my incoming calls for my business.

I can’t seem to get it to forward to voicemail without errors.

Here is how the call gets triggered.

Customer Calls -> Routes to Webhook -> Handle-Incoming-Call.XML

    <?xml version="1.0" encoding="UTF-8"?>
<Response>
    
    <Redirect>handle-extension.php</Redirect>
</Response>

Then Handle-Extension.PHP looks like this

<?php
    header('Content-type: text/xml');
    echo '<?xml version="1.0" encoding="UTF-8"?>';

    echo '<Response>';

    
        # @start snippet
        echo '<Say>Thank you for calling, My Business</Say>';
        echo '<Dial record="true" timeout="15" action="voicemail.php">';
        echo '<Number url="screen-caller.xml">+10000000000</Number>';
        echo '</Dial>';
        # @end snippet
    
    echo '</Response>';
?>

Then Screen-Caller.XML looks like this (This is what me as a business will hear when I pick up)

<?xml version="1.0" encoding="UTF-8"?>
<Response>
    <Gather action="handle-screen-input.php" numDigits="1">
        <Say>Call for Your Business</Say>
        <Say>To accept the call, press 1.</Say>
        <Say>To reject the call, press 2.</Say>
    </Gather>

</Response>

When I press 1 I get the call, but when I press 2 I want it to go to voicemial.

Here is the Handle-Screen-Input.PHP

<?php
    header('Content-type: text/xml');
    echo '<?xml version="1.0" encoding="UTF-8"?>';

    echo '<Response>';

    $user_pushed = (int) $_REQUEST['Digits'];

    if ($user_pushed == 1)
    {
        echo '<Say>Connecting, say hello.</Say>';
    }
    else {
        echo '<Hangup />';
    }

    echo '</Response>';
?>

I did a bypass for now so I created another Webhook to go to a TwimLets Forwarding Voicemail to Email when it fails.

Here is the fail message I get from LOGS

An attempt to retrieve content from https://website.com/callsystem/voicemail.php returned the HTTP status code 500. Falling back to http://twimlets.com/voicemail?Email=email%40email.com&Message=Please%20leave%20a%20message%20after%20the%20beep.&Transcribe=true&

So when it gets to the error it goes to my fallback WebHook, I still get the voicemail but I get tons of error logs at the end of the day.

I am trying to figure out what I am missing to get the voicemail.php to work.

Here is the voicemail.php code I found in one of the posts here in Stack.

header("content-type: text/xml");
    echo '<?xml version="1.0" encoding="UTF-8"?>';
    $email = $_REQUEST['email'];
?>
<Response>
    <?php if ($_REQUEST['DialCallStatus'] == 'completed') { ?>
            <Hangup/>
    <?php } else { ?>
            <Say>Sorry Our Business is not available at this time, Please leave a message at the tone.  Press the star key when finished.</Say>
            <Record transcribe="true" action="goodbye.php" transcribeCallback="voicemail-send.php?email=<?php echo $email; ?>" maxLength="120" finishOnKey="*" />
            <Say>I did not receive a recording.</Say>
            <Redirect>voicemail.php</Redirect>
    <?php } ?>
</Response>

Do I need to add a file name “voicemail-send.php” if so what is that structure look like?

Any help would be greatly appreciated. Thank you

What is the right way to add a new product property in WooCommerce?

I’ve just started learning about WordPress and WooCommerce. My problem is that products there lack properties like expiration date, origin or similar that I might think of in the future (for every single product these fields are probably going to be different, not that many duplicates). I know that it might be possible to achieve this functionality with attributes (?) but I’m not entirely sure. My idea is to create a module with a separate database which would have a relationship with each product (or post). Is that the right approach? What I am trying to achieve at the end of the day is to create a dashboard in the front end where some users will be able to add or edit certain products and those fields are necessary to be in that dashboard. Or maybe you have any other suggestions? Thank you.