“CREATE TABLE IF NOT EXISTS” does not return error if exists [closed]

This is my code:

$query = "CREATE TABLE IF NOT EXISTS `data`(`id` INT(11) AUTO_INCREMENT, `car` INT(11), PRIMARY KEY(id))";

try {
    $stm = self::$connection->query($query);
    echo 'done';
} catch (PDOException $e) {
    echo $e->getMessage();
}

This code work fine, but if table is exists, PDO not return any error for me.

I want this code:

if ($stm) {
    echo "not exists and create table";
} else {
    echo "exists!"
}

Is it safe to use MongoDB sessions with PHP-FPM (multi-threads)?

I want to use MongoDB sessions to get a causal consistency guarantee.
However I use nginx with PHP-FPM which is multi-threaded. Excluding MongoDB documentation https://docs.mongodb.com/v4.2/core/read-isolation-consistency-recency/ specifies “Applications must ensure that only one thread at a time executes these operations in a client session.”.

So I’m stuck at this level and I don’t really see how to get out of it. The only solution I see
is to make PHP-FPM single thread which I obviously do not want for the advantages it provides.

Do you have any ideas ?

Thank you,

PHP Posting variables to another page after calculation

i’m trying to post my variables “$correct” and “$incorrect” over to another page call “testresult.php”. But i can’t seem to receive the variables on the other page. Is there something wrong with my codes?

<form action="testresult.php" method="POST">
    <label for="qn1">Question 1: <?php echo $array_question[$question_num_array[0]] ?></label><br>
    <input type="text" id="question1_answer" name="question1_answer" required><br><br>
    
    <label for="qn2">Question 2: <?php echo $array_question[$question_num_array[1]] ?></label><br>
    <input type="text" id="question2_answer" name="question2_answer" required><br><br>

    <label for="qn3">Question 3: <?php echo $array_question[$question_num_array[2]] ?></label><br>
    <input type="text" id="question3_answer" name="question3_answer" required><br><br>

    <input type="hidden" name="correct" id="correct" value="<?php $correct ?>" />
    <input type="hidden" name="incorrect" id="incorrect" value="<?php $incorrect ?>" />
    
    <input type="submit" name="submitAnswers" value="Submit">
</form>

<?php
        if(isset($_POST["submitAnswers"])){
            $correct = 0;
            $incorrect = 0;
            $qn1_ans = $_POST['question1_answer'];
            $qn2_ans = $_POST['question2_answer'];
            $qn3_ans = $_POST['question3_answer'];

            if ($qn1_ans == $array_answer[$question_num_array[0]]){ $correct ++; }
            else { $incorrect ++; }

            if ($qn2_ans == $array_answer[$question_num_array[1]]){ $correct ++; }
            else { $incorrect ++; }

            if ($qn3_ans == $array_answer[$question_num_array[2]]){ $correct ++; }
            else { $incorrect ++; }

        }
    ?>

On the other page, this is my code.

<html>
    <head>
    <title>Results</title>
    </head>
    <body>
        <?php
        $correct = $_POST['correct'];
        $incorrect = $_POST['incorrect'];

        echo $correct."test ".$incorrect;
        ?>
    </body>
</html>

Problem in docker images it is not starting

I made in my project nginx, mysql, phpMyadmin, encore and php images.
Just php and encore dosent work, they are successed built, but the are with red color.

that is my docker-compose.yml:

version: '3.3'
services:
 database:
   container_name: database
   image: mysql:8.0
   restart: always
   command: --default-authentication-plugin=mysql_native_password
   environment:
     MYSQL_ROOT_PASSWORD: alsbls
     MYSQL_DATABASE: infoSystem
     MYSQL_USER: alsbls
     MYSQL_PASSWORD: alsbls
   ports:
     - '4306:3306'
   volumes:
     - ./mysql:/var/lib/mysql

 php:
   container_name: php
   restart: always
   build:
     context: ./php
   ports:
     - '9000:9000'
   volumes:
     - ./app:/var/www/infoSystem

   depends_on:
     - database

 nginx:
   container_name: nginx
   image: nginx:stable-alpine
   restart: always
   ports:
     - '8080:80'
   volumes:
     - ./app:/var/www/infoSystem
     - ./nginx/default.conf:/etc/nginx/conf.d/default.conf
   depends_on:
     - php
     - database

 phpmyadmin:
   image: phpmyadmin/phpmyadmin:latest
   restart: always
   environment:
     PMA_HOST: database
     PMA_USER: alsbls_root
     PMA_PASSWORD: alsbls_root
   ports:
     - "8081:81"

 encore:
   container_name: encore
   restart: always
   build:
     context: ./php
   volumes:
       - ./:/var/www/html

That is my Dockerfile:

FROM php:8.0-fpm
          
RUN apt update   
            && apt install -y zlib1g-dev g++ git libicu-dev zip libzip-dev zip 
            && docker-php-ext-install intl opcache pdo pdo_mysql 
            && pecl install apcu 
            && docker-php-ext-enable apcu 
            && docker-php-ext-configure zip 
            && docker-php-ext-install zip
WORKDIR /var/www/infoSystem
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
RUN curl -sS https://get.symfony.com/cli/installer | bash
RUN mv /root/.symfony/bin/symfony /usr/local/bin/symfony
RUN git config --global user.email "[email protected]" 
        && git config --global user.name  "alsbls"




FROM node:12.10.0
WORKDIR /var/www/html
COPY entrypoint.sh /usr/local/bin/entrypoint
RUN ["chmod", "+x", "/usr/local/bin/entrypoint"]
ENTRYPOINT ["/usr/local/bin/entrypoint"]
USER node

that is the entrypoint.sh in the same dir of Dockerfile:

#!/bin/bash
# Prevent container from shutting down
while true; do sleep 3600; done

I didn’t receive any error message on the terminal.
Maybe some one now the issues.

Best regards

Persisting user preference for duration of session to filter product variation prices (WordPress, Woocommerce)

I would like the know the ideal way of adding a selection to the main nav of my wordpress/woocommerce site that lets users specify what region they prefer to see prices for. All the products have four variations, each one for a specific region and price. Someone from asia should then be able to select “asia” in a dropdown or radio button and only see product prices for asia when skimming through categories.

This setting should not be persisted to disk or db, only to session or something that works similarly in WP.

At the moment I have a filter set up for “woocommerce_variable_price_html” that simply replaces the “From X – Y$” format for prices with a hardcoded region price. But instead it should use the user specified region and then default to americas if none.

Thank you in advance! Let me know if anything needs elaboration.

Problem with preparing array with attendance for team

I got Users, Absences and Reasons tables:

Users
id | name 

Absences
id | user_id:foreignKey | reason_id:foreignKey | deputy_id:foreignKey | start:date | end:date

Reasons
id | name

I got attendance calendar which looks like:

Day   | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 |
-----------------------------------------------|
User1 | o | o | V | V | S | S | o | o | o | V  |
-----------------------------------------------|
User2 | T | o | o | o | H | V | o | V | o | V  |
-----------------------------------------------|

Where “V” is Vacation, “S” sick etc. I want to print each User attendance report in that table.

@foreach ($users as $user )
   <tr>
      <td> {{ $user->name }} </td>
   @if($user->absences != null)
      @foreach($days as $day)
         @foreach ($user->absences as $absence)
           @if($day >= $absence->start->format('d') && $day <= $absence->end->format('d'))
              // there check if $user->absence->reason_id == something ...
           @else
              
           @endif
         @endforeach
       @endforeach
    @endif
  </tr>
@endforeach

Also I want to have a tooltip, where I print specific data for each day (reason name, deputy name).

I have no idea how to get the range between two dates in each absence, merge it to got f.e table of user absence days with another array with reason.:

[
  2 => ['reason_id => 1, deputy_id = 3], 
  3 => ['reason_id => 1, deputy_id = 3], 
  7 => ['reason_id => 2, deputy_id = 1]
]

Where keys [2,3,7] are the days of the absence.

Is there easier way to achieve that or should I rebuild the database structure?

Add image to PHP email template

If I add the following line into the template the checkout becomes unavailable.

"n<img src="https://example.com/images/girocode.png" alt="GiroCode" />" . 

How can I make the work in PHP?

Prepared statement always returns true, also when (previously registered) username is not found in database

next block is located in class that inherits database class,connect() is my method for connecting to a database

protected function checkUser($username){
    $searchForUser=$this->connect()->prepare('select username from users where username=?;');

    if($searchForUser->execute(array($username))){
        $searchForUser=null;
        header("location: ../login.php?error=existing_username");
        exit();
    }

    $check=false;
    if($searchForUser->rowCount()>0){
        $check=true;
    }
    return $check;
}

next block is from class that inherits a class above

private function checkForUserExistance(){
    $value = false;
    if($this->checkUser($this->username)){
        $value=true;
    }
    return $value;
}

how to solve the undefined property problem in laravel 8.7

I develop a forum module for a web site IN LARAVEL 8, I face the problem of Undefined property: AppModelsThread::$title, since 3 days I look for the solution but in vain.
Here is the code of my model

<?php
  namespace AppModels;
  use AppTraitsHasAuthor;
  use AppTraitsHasTags;
  use IlluminateDatabaseEloquentBuilder;
  use IlluminateDatabaseEloquentFactoriesHasFactory;
  use IlluminateDatabaseEloquentModel;
  use IlluminateDatabaseEloquentRelationsBelongsTo;
  use IlluminateSupportStr;
  class Thread extends Model
 {
use HasTags;
use HasAuthor;
use HasFactory;
const TABLE = 'threads';
protected $table = self::TABLE;
protected $fillable = [
    'title',
    'body',
    'slug',
    'writer_id',
    'category_id',
];
protected $with = [
    'category',
    'writer',
    'tags',];
public function category(): BelongsTo
{
    return $this->belongsTo(Category::class);
}

public function excerpt(int $limit = 250): string
{
    return Str::limit(strip_tags($this->body()), $limit);
}

public function id(): int
{
    return $this->id;
}

public function title(): string
{
    return $this->title;
}

public function body(): string
{
    return $this->body;
}

public function slug(): string
{
    return $this->slug;
}

public function delete()
{
    $this->removeTags();
    parent::delete();
}
public function scopeForTag(Builder $query, string $tag): Builder
{
    return $query->whereHas('tagsRelation', function ($query) use ($tag) {
        $query->where('tags.slug', $tag);
    });
}

code of my Controller that displays the details of the post (show)

public function show(Category $category, Thread $thread)
{
  return view('pages.threads.show', compact('thread', 'category'));
}

the different fragments of the views

  • Index

      @foreach($threads as $thread)
                         <article class="post post-medium">
                             <div class="row mb-3">
                                 <div class="col-lg-5">
                                     <div class="post-image thumb-info-wrapper border-radius-0">
                                         <a href="blog-post.html">
                                             <img src="{{asset('assets/frontend//img/blog/medium/blog-11.jpg')}}" class="img-fluid img-thumbnail img-thumbnail-no-borders rounded-0" style="width: 100px;height:100px" alt="" />
                                         </a>
                                     </div>
                                 </div>
                                 <div class="col-lg-7">
                                     <div class="post-content">
                                         <h2 class="font-weight-semibold pt-4 pt-lg-0 text-5 line-height-4 mb-2"><a href="{{ route('forums.show', [$thread->category->slug(), $thread->slug()]) }}"> {{ $thread->title() }}</a></h2>
                                         <p class="mb-0"> {{ $thread->excerpt() }}[...]</p>
                                     </div>
                                 </div>
                             </div>
                             <div class="row">
                                 <div class="col">
                                     <div class="post-meta">
                                         <span class="appear-animation"  data-appear-animation="flash" data-appear-animation-delay="0" data-appear-animation-duration="1s"><i class="far fa-calendar-alt"></i> {{ $thread->created_at->diffForHumans() }}</span>
                                         <span><i class="far fa-user"></i> By <a href="#">{{$thread->author()->name}}</a> </span>
                                         <span><i class="far fa-folder"></i> <a href="#">Lifestyle</a>, <a href="#">Design</a> </span>
                                         <span><i class="far fa-comments"></i> <a href="#">12 Comments</a></span>
                                         <a href="javascript:void(0)" class="text-muted d-inline-flex align-items-center align-middle" data-abc="true">
                                             <i class="fa fa-heart fa-spin text-danger"></i>&nbsp; <span class="align-middle">445</span> </a>
                                         <span class="text-muted d-inline-flex align-items-center align-middle ml-4">
                              <i class="fa fa-eye text-muted fsize-3"></i>&nbsp; <span class="align-middle">14532</span> </span>
                                         <span class="text-muted d-inline-flex align-items-center align-middle ml-4">
                              <i class="fa fa-comments text-muted fsize-3"></i>&nbsp; <span class="align-middle">14532</span>
                          </span>
                                         <span class="d-block d-sm-inline-block float-sm-right mt-3 mt-sm-0"><a href="{{ route('forums.show', [$thread->category->slug(), $thread->slug()]) }}" class="btn btn-xs btn-light text-1 text-uppercase">Read More</a></span>
                                     </div>
                                 </div>
                             </div>
                         </article>
                         @endforeach
    

*show

  @extends('layouts.guest')

  @section('title', 'forum')

 @push('css')

 @endpush

@section('content')
<section class="page-header page-header-modern bg-color-light-scale-1 page-header-md">
    <div class="container">
        <div class="row">
            <div class="col-md-12 align-self-center p-static order-2 text-center">
                <h1 class="text-dark font-weight-bold text-8">Medium Image Right Sidebar</h1>
                <span class="sub-title text-dark">Check out our Latest News!</span>
            </div>
            <div class="col-md-12 align-self-center order-1">
                <ul class="breadcrumb d-block text-center">
                    <li><a href="{{route('home')}}">Home</a></li>
                    <li><a href="{{route('forums.index')}}">Forum</a></li>
                    <li><a href="#">{{ $category->name() }}</a></li>
                    <li class="active">{{ $thread->title() }}</li>
                </ul>
            </div>
        </div>
    </div>
</section>
<div class="container-fluid mt-100">
    <div class="row">
        <div class="col-md-12">
            <div class="card mb-4">
                <div class="card-header">
                    <div class="media flex-wrap w-100 align-items-center"> <img src="https://i.imgur.com/iNmBizf.jpg" class="d-block ui-w-40 rounded-circle" alt="">
                        <div class="media-body ml-5"> <a href="javascript:void(0)" data-abc="true">Tom Harry</a>
                            <div class="text-muted small">13 days ago</div>
                        </div>
                        <div class="text-muted small ml-3">
                            <div>Member since <strong>01/1/2019</strong></div>
                            <div><strong>134</strong> posts</div>
                        </div>
                    </div>
                </div>
                <div class="card-body">
               <p>{!! $thread->body() !!}</p>
                </div>
                <div class="card-footer d-flex flex-wrap justify-content-between align-items-center px-0 pt-0 pb-3">
                    <div class="px-4 pt-3">
                        <a href="javascript:void(0)" class="text-muted d-inline-flex align-items-center align-middle" data-abc="true">
                            <i class="fa fa-heart fa-spin text-danger"></i>&nbsp; <span class="align-middle">445</span> </a>
                        <span class="text-muted d-inline-flex align-items-center align-middle ml-4">
                            <i class="fa fa-eye text-muted fsize-3"></i>&nbsp; <span class="align-middle">14532</span> </span>
                        <span class="text-muted d-inline-flex align-items-center align-middle ml-4">
                            <i class="fa fa-comments text-muted fsize-3"></i>&nbsp; <span class="align-middle">14532</span>
                        </span>
                    </div>
                    <div class="px-4 pt-3"> <button type="button" class="btn btn-primary"><i class="ion ion-md-create"></i>&nbsp; Reply</button> </div>
                </div>
            </div>
        </div>
    </div>
</div>
@endsection


@push('js')

@endpush

thank you for your help

Is it a bad practice to send AJAX requests with always the POST HTTP method?

I was asking myself if it was a bad practice to send every ajax request I use on my Laravel 8 project with the HTTP Post method.

What I mean is that, according to Laravel 8 documentation on routing (if I understood everything well), you should use the appropriate HTTP request :

Route::get($uri, $callback);
Route::post($uri, $callback);
Route::put($uri, $callback);
Route::patch($uri, $callback);
Route::delete($uri, $callback);
Route::options($uri, $callback);

A French tutorial on the routes explains this (translated by myself) :

GET : ask for a resource that never changes,
POST : update or create a resource (often wrongly used when PUT is needed),
PUT : create or replace a resource,
PATCH : partialy update a resource,
DELETE : delete a resource.

The “problem”, if there is one, is that in my code in almost only use HTTP post requests for AJAX in my routes/web.php file, like this :

Route::post('mails/update/{id}', 'AppHttpControllersMailController@update');
Route::post('mails/sendMail/', 'AppHttpControllersMailController@sendMailTest')->name('mails.sendMailTest');
Route::post('mails/sendInstantMail/', 'AppHttpControllersMailController@sendInstantMail')->name('mails.sendInstantMail');
Route::post('mails/getRouteList/', 'AppHttpControllersMailController@getRouteList')->name('mails.getRouteList');

According to what I read, I should probably use PUT or PATCH for my update method. But with POST it works. Is it a bad practice to continue to use POST?

If I guess right, AJAX is only a way to do HTTP request, but in fact it is still the same idea behind the request, so I should change my request methods.

I am really sorry if my question is dumb, and thanks for your help!

Sources :

Laravel 8 – Route documentation about the router methods : https://laravel.com/docs/8.x/routing#available-router-methods

French tutorial on Laravel routing see “Les méthodes” chapter : https://laravel.sillo.org/cours-laravel-8-les-bases-le-routage/

English translated tutorial with Google Translate (See “The methods” chapter) : https://laravel-sillo-org.translate.goog/cours-laravel-8-les-bases-le-routage/?_x_tr_sl=fr&_x_tr_tl=en&_x_tr_hl=fr&_x_tr_pto=wapp

Cookie-Stored Setting Not Applying

I am making a setting in my WooCommerce website where the user can choose between a table view and a grid view of the products. I use cookies for this. The setting works sometimes when clicking on it; but when changing page, when there is pagination, it doesn’t always retain the selected view.

I set the cookie like this:

document.cookie = "Techsaker_se_vyval=Rutnätsvy";

And then, in my content-product.php file I check it like this:

// If products view not set to grid, show table view
if (($_COOKIE['Techsaker_se_vyval']) != 'Rutnätsvy') {

It seems the cookie value isn’t retained.

Additionally, it will sometimes also show the table view on one page of a product category, and then the grid view on a different page.

I have also observed that if I print the cookie value to the console with console.log, the value is often different from when I print it from the php with:

var_dump($_COOKIE['Techsaker_se_vyval']);

For example when I tested this, they showed conflicting values on page 1 of my shop startpage and the same values on page/2/. And I could only change the value successfully on page 2.

After further tests, I observed that the JavaScript and php sometimes do show the same value also on page 1, but even then, I couldn’t change the view on page 1. On clicking on an option, the JavaScript value in the console sometimes changes without changing the view printed, sometimes not even that. However; in a product category, as opposed to the shop startpage, I have seen that sometimes I can change the view on both page 1 and page 2.

It’s always the php value that determines what view is output. Why isn’t it always registering the same value as the JavaScript?

And changing the view always seems to work when it’s on page 2.

Does anyone know why this could be happening?

Thank you!

Why does if($x = 1 && $x == 1) throw error but if ($x == 1 && $x = 2) doesn’t in php?

In php the following code throws error:

if($x = 1 && $x == 1)

I’ve been told, it’s because && has higher precedence than =, which cases the expression to get converted to:

if($x = (1 && ($x == 1)))

So far so good, but now consider:

if $x=1; ($x == 1 && $x = 2)

This doesn’t throw error. Why doesn’t it get converted to:
if $x=1; (($x == 1) && $x) = 2)

I’ve been told thats due to = being right assosiative, but https://www.php.net/manual/en/language.operators.precedence.php says When operators have equal precedence their associativity decides how the operators are grouped.. Here we have =, && and == all being of different precedence.

P.S; My actual code is if($result != false && $res = $stmt->get_result()), which has been copied from some other reputable source, so seems like not using unneeded parenthesis is common in php.

how do I prevent form from checking at the current session?

enter image description here

enter image description here

The ones checked are the correct answer to the question. But when I click on the submit button, the questions changes and state the answers are wrong. I’ve tried too fix it by using the GET method. But that didn’t work either.

The result I am trying to get it have 3 random questions. Which are stored in an array with it’s options and answer. When the 3 questions are displayed, the options will be displayed with it. When the user clicks on the correct answer it should display the correct result, but it is not able to at the moment.

Let me include the code below.

    <?php
    /*-----------------------------------Generate 3 Random Questions ----------------------------------------- */
    /*Array Random Function*/
    $pickqns_key = array_rand($qnPool,3);
    //var_dump($pickqns_key); ----- Test if Array is sucessfully randomise with 3 questions

    /*Store 3 Question into an Array using the key generated*/
    $qns_3 = array();
    $i = 0;

    foreach($pickqns_key as $key){
        $qns_3[$i] = $qnPool[$key];
        $i++;
    }
    /*Individual Question List*/
    $question1 = $qns_3[0]["qns"];
        $q1option1 = $qns_3[0]["ops"][0];
        $q1option2 = $qns_3[0]["ops"][1];
        $q1option3 = $qns_3[0]["ops"][2];
            $q1ans = $qns_3[0]["ans"];
            var_dump($qns_3[0]);
            var_dump($q1ans);
    $question2 = $qns_3[1]["qns"];
        $q2option1 = $qns_3[1]["ops"][0];
        $q2option2 = $qns_3[1]["ops"][1];
        $q2option3 = $qns_3[1]["ops"][2];
            $q2ans = $qns_3[1]["ans"];
            var_dump($qns_3[1]);
            var_dump($q2ans);
    $question3 = $qns_3[2]["qns"];
        $q3option1 = $qns_3[2]["ops"][0];
        $q3option2 = $qns_3[2]["ops"][1];
        $q3option3 = $qns_3[2]["ops"][2];
            $q3ans = $qns_3[2]["ans"];
            var_dump($qns_3[2]);
            var_dump($q3ans);
<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <title>Final Exam</title>
        <meta name="description" content="">
        <meta name="viewport" content="width=device-width, initial-scale=1"><!--Please remember to change style sheet for each page-->
        <link rel= "stylesheet" href="styles/qn_History.css" type="text/css"/> 
    </head>
    <body>
        <header>
            <img class="logo" src ="source/images/nav_logo.png" alt="logo">
                <!------------Nav Bar-------------------->
                <nav>
                <ul class ="nav__links">
                  <li><a href="index.php">Home</a></li>
                  <li><a href="qn_History.php">History</a></li>
                  <li><a href="qn_Math.php">Mathematics</a></li>
                  <li><a href="#">Contact Us</a></li> <!--This contact us page is stated here just for show. If we have time we can create a simple form that doesn't work-->
                </ul>
                </nav>
        </header>
        
        <!-- This is where the main content for your webpages are going to be-->
        <div class ="quiz_box">
            <h2>History Questions - Answer Qn 1 - 3</h2>
            <div class="std_id">
                <?php
                    //$student_ID = $_GET['studentNum'];
                    //echo "<h3>Student No: $student_ID </h3>"; 
                ?>
            </div>
            <div class="history_qn">
                <form action="qn_History.php" method="POST">
<!------------------------------------History - Question 1 ------------------------------------------------------------->
                    <div class="qn">
                       <?php 
                            /*1st Trial at Printing Question and Radio Button*/
                            //$qn_counter = 1;
                            /*Printing out each Question from the Array*/
                            //foreach($qns_3 as $qns_No => $value){
                                //echo $qn_counter,". ",$value['qns'],"<br>";
                                /*Printing Out Radio Buttons of Options8*/
                                /*foreach($value['ops'] as $options){
                                    echo '<input type="radio" name= $qns_3 = $options>',$options,"<br>";
                                }
                                $qn_counter++;
                            }*/
                        ?>
                        <p>1. <?php echo $question1 ?><p></p>
                        <!--Option 1 -->
                        <input type ="radio" id ="q1o1" name = "qn1" value ="<?php echo $q1option1?>"/>
                        <label for ="q1o1"><?php echo $q1option1 ?></label><br>

                        <!--Option 2 -->
                        <input type ="radio" id ="q1o2" name = "qn1" value ="<?php echo $q1option2?>"/>
                        <label for ="q1o2"><?php echo $q1option2 ?></label><br>

                        <!--Option 3 -->
                        <input type ="radio" id ="q1o3" name = "qn1" value ="<?php echo $q1option3?>"/>
                        <label for ="q1o3"><?php echo $q1option3 ?></label><br>

                        <!-- Qn3 Action Handler-->
                        <div class = "action_handler">
                            <?php
                                $counter = 0;
                                if(isset($_POST['qn1'])){
                                    $ans1 = $_POST['qn1'];
                                    var_dump($ans1);
                                }
                                else{
                                    $ans1 = NULL;
                                }

                                if($ans1 != NULL){
                                    if($ans1 != $q1ans){
                                        echo "$ans1 is incorrect";

                                    }
                                    else{
                                        echo "$ans1 is correct";
                                        $counter += 1;                                        
                                    }
                                }
                                else{
                                    echo "Select an answer for Qn.1 <br>";
                                }
                            ?>
                        </div>
                    </div>
                    <br>

<!------------------------------------History - Question 2 ------------------------------------------------------------->
                    <div class="qn">
                        <p>2. <?php echo $question2 ?></p>
                        <!--Option 1 -->
                        <input type ="radio" id ="q2o1" name = "qn2" value ="<?php echo $q2option1?>"/>
                        <label for ="q2o1"><?php echo $q2option1 ?></label><br>

                        <!--Option 2 -->
                        <input type ="radio" id ="q2o2" name = "qn2" value ="<?php echo $q2option2?>"/>
                        <label for ="q2o2"><?php echo $q2option2 ?></label><br>

                        <!--Option 3 -->
                        <input type ="radio" id ="q2o3" name = "qn2" value ="<?php echo $q2option3?>"/>
                        <label for ="q2o3"><?php echo $q2option3 ?></label><br>
                        <div class="action_handler">
                            <?php
                                if(isset($_POST['qn2'])){
                                    $ans2 = $_POST['qn2'];
                                    var_dump($ans2);
                                }
                                else{
                                    $ans2 = NULL;
                                }
                            
                                if($ans2 != NULL){
                                    if($ans2 != $q2ans){
                                        echo "$ans2 is incorrect";
                                    }
                                    else{
                                        echo "$ans2 is correct";
                                        $counter += 1;
                                    }
                                }
                                else{
                                    echo "Select an answer for Qn.2 <br>";
                                }
                            ?>
                        </div>
                    </div>
                    <br>

<!------------------------------------History - Question 3 ------------------------------------------------------------->
                    <div class="qn">
                    <p>3. <?php echo $question3 ?></p>
                        <!--Option 1 -->
                        <input type ="radio" id ="q3o1" name = "qn3" value ="<?php echo $q3option1?>"/>
                        <label for ="q3o1"><?php echo $q3option1 ?></label><br>

                        <!--Option 2 -->
                        <input type ="radio" id ="q3o2" name = "qn3" value ="<?php echo $q3option2?>"/>
                        <label for ="q3o2"><?php echo $q3option2 ?></label><br>

                        <!--Option 3 -->
                        <input type ="radio" id ="q3o3" name = "qn3" value ="<?php echo$q3option3?>"/>
                        <label for ="q3o3"><?php echo $q3option3 ?></label><br>
                        <div class="action_handler">
                        <!-- Qn3 Action Handler-->
                            <?php
                                if(isset($_POST['qn3'])){
                                    $ans3 = $_POST['qn3'];
                                    var_dump($ans3);
                                }
                                else{
                                    $ans3 = NULL;
                                }
                            
                                if($ans3 != NULL){
                                    if($ans3 != $q3ans){
                                        echo "$ans3 is incorrect";
                                    }
                                    else{
                                        echo "$ans3 is correct";
                                        $counter += 1;
                                    }
                                }
                                else{
                                    echo "Select an answer for Qn.3 <br>";
                                }
                            ?>
                        </div>
                    </div>
                    <!--End of History Quiz -->
                    <br>
                        <input type="submit" name="submit" value="Submit Quiz" class ="btn"/>
                        <a href="resultpage.php" class="result-btn">View results</a>
                    </div>
                <div class ="results">
                    <?php
                        echo "<h3>Your score for this History Quiz is $counter / 3</h3>";
                    ?>
                </div>
                </form>
            </div>