I suspect the cause of your problems is here:
$video = $_POST['subject'];
if ($video == true){
For example, if our subject is https://www.youtube.com/watch?v=dQw4w9WgXcQ then the check is:
if ( 'https://www.youtube.com/watch?v=dQw4w9WgXcQ' == true )
And we know that true
is not https://www.youtube.com/watch?v=dQw4w9WgXcQ
, so the check here is incorrect. What we want is to check if $video
contains something other than an empty value:
if ( ! empty( $video ) ) {
I would also recommend placing the form handler code before the form, not afterwards, and using escaping functions on the output. Right now someone could put a script tag in the input box and execute arbitrary javascript on the site