help w/redirect

Hi, This little program checks to see if the contract is valid. I have a database field "expiry"
(int 3) from which 1 is subtracted when run. As long as the expiry is above 0 I want to redirect to
"sysnav.html", otherwise I want to redirect to "expiredpage.html". I need help w/the redirects.Quoted Text Here

<?php
$link = mysqli_connect("localhost", "root", "", "prerentdb"); 
// Check connection
if($link === false){ die("ERROR: Could not connect. " . mysqli_connect_error()); }

$id='id';
echo "<center>";echo date('m/d/y');echo "<br />";

// Attempt select query execution
$result = mysqli_query($link,"SELECT * FROM numbers");
$row= mysqli_fetch_array($result);

$id='id';
$expiry='expiry';
if ($_POST["expiry"] === $_POST["confirm_password"]) {

$sql = "UPDATE numbers SET expiry = $expiry-1 where id=$id  ";
if(mysqli_query($link, $sql)){ echo "expiry was updated successfully."; } 
else { echo "ERROR: Could not able to execute $sql. " . mysqli_error($link); }

if ($expiry == 0) // go to expiredpage.html
 { 
header("location:expiredpage.html");
 } 

else  // go to sysnav.html
  { 
header("location:sysnav.html");
 } 
// Close connection
mysqli_close($link);
?>

the result:
even though expiry is 300, I get this:
Your contract has expired.
Contact the webmaster hereQuoted Text Here

Automattic Releases Quadrat, a Block-Based Podcasting WordPress Theme

Screenshot of the Quadrat WordPress theme with its Episode pattern on the homepage.

A few weeks ago, Automattic released Quadrat on the WordPress.org theme directory. It is now the company’s fourth block theme. Like its predecessors, it is a child of Blockbase, a project that serves as a foundation for the work of Automattic’s Theme Team.

After spending a couple of months diving deep into the world of block themes, I was beginning to feel a little burned out. When I wasn’t sleeping, eating, or doing yard work in my off-duty time, I was building or exploring one project or another. Soon, it all had become a blur. I knew I needed to take a small break, and I have not touched themes for a couple of weeks since, at least not outside of work.

However, Quadrat appealed to the theme developer within me. I am not sure if it was the soothing color scheme or just seeing the work the professional designers had put into it, but it offered a pathway for easing myself back into the block theme world.

Outside of the work by Anariel Design with Naledi and Clove, most block themes have felt more like proof of concepts or starting points. Quadrat can now be added to the list of those with some personality.

It does not push any particular boundaries, but it is a well-designed blogging and podcasting theme. Mostly, I am just a fan of the color scheme — sometimes you just need something other than black, white, and gray to get yourself out of a funk.

One of the other reasons I have been following the work of the Quadrat theme was because it was the first showcase of header patterns I had seen. Kjell Reigstad shared what this system would look like in June.

The goal is to include the patterns shown in the video in core WordPress, so they are not currently included in the theme. However, there is still an open ticket for header patterns in Quadrat.

The only real trouble I ran into with the theme is with fully aligned blocks in the content. There is an overflow issue in version 1.1.1 that creates a horizontal scrollbar.

Hoziontal scrollbar when using a full-width block with the Quadrat theme.
Horizontal scrollbar appears with full-width Cover block.

Quadrat includes nine custom patterns. The focus for most is on podcasting, but some are general-purpose enough for other use cases, such as “Media and text with button”:

Illustration in the left column and Heading and Button blocks in the right in a pattern built with the Media & Text block in the WordPress editor.
Media and text with button pattern.

The development team missed a prime opportunity with its podcast-related patterns. Instead of integrating with a podcasting solution, they are simple, static blocks from core WordPress.

For example, the Latest Episodes pattern is a two-column layout that features Image, Heading, and Paragraph blocks. That is acceptable as a base pattern for users without a podcasting plugin. However, it may be practically useless for those with one enabled. Or, it creates unnecessary work because users must manually update their page content anytime they publish a new episode.

Two-column layout with Image, Heading, and descriptive text of podcasting episodes.
Latest Episodes block pattern

Given Automattic’s recent bet on Castos as part of a $756K pre-seed fundraising round, it would make sense to integrate with the podcasting company’s plugin, Seriously Simple Podcasting (SSP).

If the development team wanted to take the Latest Episodes pattern to the next level, they would create it with the Query Loop block and display the latest podcast episodes from the plugin. For users without SSP installed, simply fall back to the current pattern. Or, offer both. Right now, it is little more than eye candy and not nearly as useful as it could be for real-world use cases.

I often talk about the need for theme authors to elevate their game. Not only would such integration be beneficial to podcasters, but it would also showcase the power and flexibility of the block system.

All of this is to say: If you are going to build a podcasting theme, build a podcasting theme. Quadrat appears to be one. However, when you peek behind the curtain, it is just a well-designed blogging theme. It has the potential to be so much more.

Measuring Developers Isn’t Tyranny

Informing someone that you want to “measure” them is not a great way to start a conversation. Software developers, like all people, tend to look unfavorably upon having their performance closely measured. But measuring developers is one of the hottest trends for companies around the globe. So is it tyranny to measure people?

People are quick to note that numbers don’t tell the whole story and can become defensive at the notion their productivity should be quantified somehow. This resistance can become even more entrenched when teams become stacked against each other. 

Seven Automation Workflows to Increase Productivity for Your Team

Automation is not always about towering robotics! Sometimes, it can be as simple as software applications cutting down repetitive tasks, thereby making time for more significant to-dos. And it’s often referred to as workflow automation. 

According to the World Wide Web, workflow automation is a series of automated actions replacing manual steps to save time and resources in everyday business processes.

Error Handling in Camunda

In this tutorial, we are going to learn about how to handle exceptions in Camunda. For this

Create a Spring Boot project with the embedded Camunda Engine using this link. Use version 7.15.0.

Mobile Commerce Testing: How Global Leaders Optimize User Experience

Mobile accounts for over 67% of all e-commerce sales worldwide and it’s expected to keep growing as more people are getting used to shopping on their phones. Nearly four out of five smartphone users have made at least one purchase in the last six months.

Since mobile performance directly affects user experience, retention rates, conversions, and ultimately revenue, improving it has become a top priority for mobile commerce companies globally.

How to create a RESTful API with Spring Boot

How to create a RESTful API with Spring Boot
Introduction

This tutorial teaches you how to create a Spring Boot application that provides RESTful API Endpoints. These endpoints are best consumed by other applications or for integrating with a SPA (Single Page Application) frontend such as Angular.

For the purpose of this tutorial, we will create a web service for managing students and their grade(seniority) for a highschool. I will refer to the application as App from now on.

Goals

At the end of this tutorial, you would have learned:

  1. How to create a Spring Boot project.
  2. How to create a @RestController to handle HTTP requests.
  3. How to create a @Service to perform business logic.
  4. How to create a @Repository to perform CRUD operations.
Prerequisite Knowledge
  1. Basic Java knowledge, especially with Java Annotations.
  2. Basic understanding of Dependency Injection.
  3. Basic understanding of HTTP requests.
  4. Familiarity with at least one Java IDE such as Eclipse, IntelliJ, Visual Studio Code(with Java extensions), or Netbeans, etc.
  5. Basic SQL or JDBC.
Tools Required
  1. Eclipse IDE for Java Developers, version 202106 R. Although IntelliJ is the most popular Java IDE right now, Spring integration in IntelliJ requires the non-free Ultimate edition. I chose to stick with Eclipse to ensure that most of my readers can follow the tutorial for free.
  2. Postman API Client. The free tier is enough for this tutorial.
Spring Initilizr

For new Spring projects, the recommended way is to use Spring Initilizr.

https://start.spring.io/ is an official Spring website that generates Spring project files for you. You can quickly choose the dependencies that you want as well as setting project metadata. Even if a lot of IDEs support creating Spring projects locally or via a plugin, such as Spring Tools, I still prefer using the official web based Spring Initilizr if I want the latest version. For that reason, my instructions will be based on the web version.

Follow the instructions below to generate our project files:

  1. Go to https://start.spring.io/
  2. Under Project, select Gradle (or Maven if you are familiar with it. For brevity, I will stick to Gradle in this tutorial).
  3. Under Language, select Java.
  4. Under Spring Boot, select version 2.5.3, which is the latest stable version.
  5. Under Project Metadata, modify the default Group to com.school
  6. For Artifact, change to app
  7. For Name, change to Student Management
  8. For Description, change to RESTful Spring project
  9. You should see the Package name already set to the correct package name of com.school.app
  10. For Packaging, select Jar
  11. For the Java version, select 16
  12. On the right hand side, you will see the Add Dependencies button, select it and add the following dependencies:
  • Spring Web.
  • Spring Data JDBC.
  • H2 Database.

Your Spring Initilizr should now look like the screenshot below.
spring_init.png

Click on the Explore button to inspect the project file structure and the generated build.gradle file. The content should be the same as my build.gradle file.

    plugins {
    id 'org.springframework.boot' version '2.5.3'
    id 'io.spring.dependency-management' version '1.0.11.RELEASE'
    id 'java'
    }
    group = 'com.school'
    version = '0.0.1-SNAPSHOT'
    sourceCompatibility = '16'
    repositories {
    mavenCentral()
    }
    dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-data-jdbc'
    implementation 'org.springframework.boot:spring-boot-starter-web'
    runtimeOnly 'com.h2database:h2'
    testImplementation 'org.springframework.boot:spring-boot-starter-test'
    }
    test {
    useJUnitPlatform()
    }

Click on Generate at the bottom left of the screen to download the generated profile files.

Extract the app folder inside the zip file. The files inside the app folder should be the same as the screenshot below.
extract.png

Import project files into Eclipse
  1. In Eclipse, click on Files -> Import
    import.png

  2. Expand Gradle -> Existing Gradle Project -> Next
    next.png

  3. For Project root directory, select Browse, then find and select the lowermost app folder (but not go inside of it) > Select Folder
    app.png

  4. The Project root directory should now be similar to this path:
    C:\Users\username\Downloads\app\app

  5. Click Next.

  6. On the next screen, you can skip overriding project workspace settings, and click Next again. After you click Next here, Eclipse will take some time to configure your project.

  7. You should now see this screen.
    gradle.png

  8. Click Finish and wait for Eclipse to build your project dependencies.

  9. Once the dependencies are done building, you should see your project below with a similar directory structure.
    project.png

  10. At the bottom of Eclipse, there is a tab called Gradle Tasks. You will find pre-built Gradle tasks(run, test, create jar) that Spring Initilizr built for you, so you dont have to configure run configurations yourself. If you cannot see the Gradle Tasks tab, then you can go to Window -> Show View -> Other -> Gradle Tasks to enable it.

  11. Now expand the application folder under Gradle Tasks, then double click on the task bootRun.
    bootrun.png

  12. Although the App does not do much yet, you should still see Spring Boot starting in the Console view.
    Started StudentManagementApplication in 2.338 seconds (JVM running for 2.812)

The Object Models

Because we want to focus on creating a RESTful API, it is best to keep our object models simple and easy to understand. We will only need two POJOs(Plain Old Java Object) for our App:

  • The Student class contains 3 fields: the name of the student and the grade that they belong to.
  • The Grade enum, with each constant representing a specific grade.

The UML diagram below depicts the relationship between Student and Grade.
uml.png

Creating POJOs

Now that we understand how our object models, let us create the Java classes for them with the steps below.

  1. Create the com.school.app.pojos package. We can create a new package by right-clicking on the com.school.app package -> New -> Package
    package.png

  2. Inside the New Java Package wizard, type in com.school.app.pojos for the Name field, and then click Finish.
    pojo.png

  3. Inside the pojos package that we just created, create a new Class by right-clicking on the package -> New -> Class
    class.png

  4. Type in Student for the Name field, and then click Finish.
    studentname.png

  5. You do not have to write any code for the Student class for now. We need to go ahead and create the Grade enum first. Right click on the pojos package again -> New -> Enum.
    enum.png

  6. For the Name, put in Grade and click Finish
    grade.png

  7. You will see an empty enum created, you can add in the constants yourselves, or you can copy the whole enum class here:

     package com.school.app.pojos;
    
     public enum Grade {
         FRESHMAN, SOPHOMORE, JUNIOR, SENIOR
     }

Now copy the content of the Student class from the source code below.

package com.school.app.pojos;

import java.util.Objects;

import com.fasterxml.jackson.annotation.JsonProperty;

public class Student {
    private final String name;
    private final Grade grade;

    public Student(
            @JsonProperty("name")String name,
            @JsonProperty("grade")Grade grade) {
        this.name = name;
        this.grade = grade;
    }

    public String getName() {
        return name;
    }

    public Grade getGrade() {
        return grade;
    }

    @Override
    public int hashCode() {
        return Objects.hash(grade, name);
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj)
            return true;
        if (obj == null)
            return false;
        if (getClass() != obj.getClass())
            return false;
        Student other = (Student) obj;
        return grade == other.grade && Objects.equals(name, other.name);
    }

    @Override
    public String toString() {
        return "Student [name=" + name + ", grade=" + grade + "]";
    }

}
The Front Controller Pattern

Before going further, we need to discuss one of our project dependencies, Spring Web MVC.

Even though the acronym MVC is in the name, Spring Web MVC is designed around the Front Controller Pattern, where a central DispatcherServlet sits in the front of the application intercepting requests.

Business logic, persistency, and view rendering would be delegated to other components, namely:

  • Business logic would be performed by the Service layer.
  • CRUD operations would be performed using the Repository layer.
  • View resolution would be performed by the View layer.

Most of the time, the View layer is only used for rendering web pages for Multi-Page Application(MPA) frontends. Because our App mostly sends and receives HTTP requests and responses, we would not need a View layer for this tutorial, but we are still going to need a Service(Business) layer and a Repository(Persistence) layer.

Below is an over-simplified diagram of our App architecture.
arch.png

Please note that I skipped over a lot of components, but I am only able to do that because Spring Boot already abstracted a lot of boilerplate code and configurations.

Even though Spring Boot allows developers to create web applications with just a few lines of code, a lot of developers would agree that Spring Boot performs too much magic and it can be hard to understand what is going on behind all of the abstractions. The chart above should be enough to provide a rough mental image that corresponds with the classes we will create later.

Creating the Controller, Service, and Repository

Because we already went over how to create packages and classes, I will skip the IDE specific instructions from now on. Let us create our Controller, the Service layer, and the Repository layer by following the steps below.

Create 3 packages:

  • com.school.app.controllers
  • com.school.app.services
  • com.school.app.repos

Insides these newly created packages, create 3 classes:

  • com.school.app.controllers.CustomRestController
  • com.school.app.services.CustomService
  • com.school.app.repos.CustomRepo

Create an empty file under src/main/resources with the name schema.sql

Paste the content below into CustomRestController.

    package com.school.app.controllers;

    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.web.bind.annotation.DeleteMapping;
    import org.springframework.web.bind.annotation.GetMapping;
    import org.springframework.web.bind.annotation.PostMapping;
    import org.springframework.web.bind.annotation.RequestBody;
    import org.springframework.web.bind.annotation.RequestParam;
    import org.springframework.web.bind.annotation.RestController;

    import com.school.app.pojos.Student;
    import com.school.app.services.CustomService;

    @RestController
    public class CustomRestController {

        @Autowired
        private CustomService service;

        @PostMapping("/addStudent")
        public void addStudent(@RequestBody Student student) {
            service.addStudent(
                    student.getName(),
                    student.getGrade());
        }

        @GetMapping("/getStudent")
        public Student getStudentByName(@RequestParam("name") String name) {
            return service.getStudentByName(name);
        }

        @DeleteMapping("/removeStudent")
        public void deleteStudentByName(@RequestParam("name") String name) {
            service.deleteStudentByName(name);
        }

    }

Paste the content below into CustomRepo.

    package com.school.app.repos;

    import java.sql.ResultSet;
    import java.sql.SQLException;

    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.jdbc.core.JdbcTemplate;
    import org.springframework.jdbc.core.RowMapper;
    import org.springframework.stereotype.Repository;

    import com.school.app.pojos.Grade;
    import com.school.app.pojos.Student;

    @Repository
    public class CustomRepo {

        @Autowired
        private JdbcTemplate jdbcTemplate;

        public int insertStudent(String name, Grade grade) {
            return jdbcTemplate.update(
                    "INSERT INTO students (name, grade) VALUES (?, ?)",
                    name, grade.toString());
        }

        public Student getStudentByName(String name) {
            String query = "select * from students where name = ?";
            return jdbcTemplate.queryForObject(query, new StudentRowMapper(), name);
        }

        public int deleteStudentByName(String name) {
            return jdbcTemplate.update(
                    "DELETE from students WHERE name = ?", name);
        }
    }

    class StudentRowMapper implements RowMapper<Student> {
        @Override
        public Student mapRow(ResultSet rs, int rowNum) throws SQLException {
            var student = new Student(
                    rs.getString("name"),
                    Enum.valueOf(Grade.class, rs.getString("grade")));

            return student;
        }
    }

Paste the content below into CustomService.

    package com.school.app.services;

    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.stereotype.Service;

    import com.school.app.pojos.Grade;
    import com.school.app.pojos.Student;
    import com.school.app.repos.CustomRepo;

    @Service
    public class CustomService {

        @Autowired
        CustomRepo repo;

        public void addStudent(String name, Grade grade) {
            repo.insertStudent(name, grade);
        }

        public Student getStudentByName(String name) {
            return repo.getStudentByName(name);
        }

        public void deleteStudentByName(String name) {
            repo.deleteStudentByName(name);
        }

    }

Paste the content below into schema.sql. This file allows Spring Boot to initialize the in-memory H2 database for us.

    create table students(
        name varchar_ignorecase(50) not null primary key,
        grade enum('FRESHMAN', 'SOPHOMORE', 'JUNIOR', 'SENIOR')
    );

    INSERT INTO students (name, grade) VALUES ('John', 'FRESHMAN');
    INSERT INTO students (name, grade) VALUES ('Mary', 'SOPHOMORE');
    INSERT INTO students (name, grade) VALUES ('Tom', 'JUNIOR');
    INSERT INTO students (name, grade) VALUES ('Jessica', 'SENIOR');

Here is how your project structure should look like at this step.
projectStructure.png

If the App is running, stop it by selecting the red stop button in the Gradle Executions tab.
gradle_stop.png

After the App has been stopped, go ahead and start it again. If your App fails to start, please go back to the previous steps to ensure that you have done everything correctly.

HTTP Requests with Postman

Now that our backend is completed, we need to fire up some requests to make sure that it works correctly. Since Postman is a popular tool, a tutorial on it is out of scope for this tutorial. I am going to assume that you already know how to use it.

Our App starts at http://localhost:8080, so we need to create the following requests:

GET:

  • localhost:8080/getStudent?name=John
  • localhost:8080/getStudent?name=Mary
  • localhost:8080/getStudent?name=Tom
  • localhost:8080/getStudent?name=Jessica
  • localhost:8080/getStudent?name=Rebecca

POST:

  • localhost:8080/addStudent
    with json body

    {"name":"Rebecca","grade":"SOPHOMORE"}

DELETE:

  • localhost:8080/removeStudent?name=Tom

After you are done creating the requests, your screen should look similar to the screenshot below.
postman.png

Test the App

If we look back at the schema.sql file we created earlier, we already created 4 students in our database when the App was bootstrapping. The first 4 GET requests were created for them. If you execute these 4 GET requests, you should see the server responding with a json object representing the student and status 200.
200.png

The 5th GET request was meant to query a student named Rebecca that is not in the database yet. If you query it now, you will receive an error code 500.
500.png

To be able to query Rebecca, we would have to add her to the database first with the POST request. Make sure to double check that the request body contains the json object before sending the request.
rebecca.png

After your POST request is accepted by the server, you should be able to query her successfully.

Finally, we need to try out the DELETE request. This request utilizes the header parameters (just like the GET requests), so should be ready to go. Fire off the DELETE request, and then try to query for Tom again. Tom has been deleted with your DELETE request, so the server will return an error 500.

CAUTION
  • The App that we created is only for demonstration purposes. It does not have the necessary security configurations to be a production server.
  • The embedded H2 Database is in-memory only. Your data will not persist after application reboot.
Summary

Congratulations, you have completed the tutorial.

The source code used in this project is located in https://github.com/dmitrilc/DaniWebSpringBoot if you want to download the project files.

Creating a Secure REST API in Node.js

Table of Content

  1. Introduction
  2. The Importance of Node.js for Rest API!
  3. What is REST and how does it blend with Node.js?
    1. Creating and Securing RESTful APIs in Node.js!
    2. Creating your first app Express API
    3. Creating the User Module
    4. Creating the Auth Module
  4. Conclusion

1. Introduction

The hype of Application programming interfaces (APIs) is universal. They enable software to interact with internal and external parts of the software, which is an essential element in scalability and reusability.

It’s considerably popular nowadays for online assistance to have public APIs. These allow other developers to quickly combine features such as social media logins, credit card debts, and performance tracking. 

Low-Code Enterprise Application Development: The Future of Technology

FACT CHECK: Low-code Enterprise Application Development is the Future of Technology

What is enterprise application development if not making business-centric apps which help companies make money?! While that is a rough description of apps per se, it holds a deeper meaning in terms of usability, customer care and service, and, most of all, in terms of branding. 

Five Developer Secrets to Speeding Mobile DevSecOps

Mobile app dev teams looking to deliver innovative, high-quality mobile apps quickly to meet their business demands, must include security as early as possible and throughout the software development lifecycle (SDLC). While mobile has become the dominant means of accessing information, mobile DevSecOps maturity frequently lags behind web DevSecOps. If the security strategy is to test right before release then rush to fix security bugs, releases are often delayed or insecure code ships — but it doesn’t have to be that way. 

Imagine spending months designing and developing a mobile app. Suddenly your project grinds to a halt during late-stage testing because a third-party API or library leaks data or a mobile app to server connection is misconfigured. You miss the release date and tempers flare.

Comparing Test Results in JMeter

Introduction

As performance testers, we are often asked to compare the difference in the performance between two versions of an application. Whatever the changes made in the second version (i.e., usage of new libraries, change of technological stack, etc.), ultimately, the business wants to know if the second version is better (or worst) and by how much.

This article discusses two solutions, including one based on a new JMeter plugin to help you "gauge" the improvement or degradation brought along by the second version of the application.

Symfony vs Laravel: Why Symfony Is Better Than Laravel

When it comes to web development, PHP frameworks are the most frequently chosen solutions. Even though there are numerous PHP frameworks available, Symfony and Laravel are the most frequently used ones. There are numerous reasons for their popularity and these range from excellent code to allow developers to create amazing apps.

In order to help you choose the right PHP framework for your next project, we compared both Symfony and Laravel to assist you in your decision-making.

Go Low-Code or go Extinct

500 years ago there existed an entire industry based upon copying books by hand. Typically the process was done by monks, sitting in monasteries, often worshipped as semi-gods may I add. 50 years later the industry was replaced by the printing press in its entirety, and none of these guys could hold their jobs.

A slightly more recent example can be found by looking at the process of manufacturing cars. When Henry Ford created his first car, it took 18 months to assemble a car, and the process typically included dozens of humans, working non-stop on the same car for 18 months. 20 years after Ford created his first factory, he was rolling out a car in 3 weeks.

AWS vs. Google Cloud: Comparing the Giants

AWS and Google Cloud are two key rivals in the world of cloud computing and storage. While the first one is winning people’s hearts with its amazing flexibility and ample features, Google Cloud has managed to firm its feet in the industry with its superb backup services and cost-effectiveness. These two are performing such wonderfully at their respective fronts that it’s tough to pick one out of these two.

If you’re also at the crossroads of picking one, let’s help you decide. In this blog post of AWS VS Google Cloud 2021, we have covered few key differences between these co-workers cloud computing giants. Before we get into the details, let’s figure out the basics of these two.

Setting up Modern Web Test Automation Framework with Selenium and Python

Nowadays, it has been a dominant trend to deploy big releases on an infrequent basis without sacrificing the quality of the product. With Every new deployment that introduces new features, bug fixes need in-depth end-to-end testing to ensure the success rate of deployment. The small product or projects can be covered up with manual testing but the products or applications that are huge in amount of features definitely require automation testing to provide maximum test coverage in minimum time. Such use cases can be achieved with the use of Selenium with any robust programming language, in this post we will be using Selenium with Python.

Selenium WebDriver is a web framework that permits the automation of web-based applications on various supported browsers like Chrome, Firefox, Safari, etc. The selenium test automation framework enables you to define step-by-step interactions with a web application and adding assertions to uncover maximum bugs.