PHP MySQL Travel History Questionnaire during Covid19

This is a simple single page PHP and MySQL based Questionnaire regarding travel history during Covid19.

You will see a questionnaire page asking you 5 questions:

  1. Your name
  2. Phone number
  3. Have you been to China in last 2 weeks?
  4. Have you travelled out of Singapore in the last 2 weeks?
  5. Body temperature

When you click submit button, your entered data will be submitted and recorded in MySQL database.

You can switch to see between form page and record page by clicking a link at the bottom of these pages.

Lorem Ipsum Cakes V2 – Simple Cake Shop Online Order System

Lorem Ipsum Cakes V2 is a simple cake shop online order system using HTML5 and PHP. It simply record client’s orders on your website database and your client can simply chat with you by using WhatsApp, either web version on their desktop devices or mobile phones using installed WhatsApp app.

How to list all files in a directory and read each of them in PHP

This code snippet is useful to me when I need to read all files inside a directory and showing it on web browser in PHP:

<?php
header('Content-type: text/plain; charset=utf-8');
$dir = "1"; //this is a folder containing files we want to read.
$files = scandir("$dir");
foreach($files as $key=>$value){
	if(!in_array($value, array(".", ".."))){
		echo "Found this file: " . $value . "<br>Begin reading...";
		$currentfile = fopen($dir . "/" . $value, "r") or die("Unable to read the file!");
		echo fread($currentfile, filesize($dir . "/" . $value));
		echo "Reading finished.";
	}
}

One line PHP code to remove characters except numbers and letters

I found this few lines of PHP script useful to sanitize user input, it removes characters except numbers and letters:

$clean_code = preg_replace('/[^\w]/', '', $string);

Or this one:

$clean_code = preg_replace('/[^a-zA-Z0-9]/', '', $string);

Original post is here: https://coderwall.com/p/bn47ka/remove-all-characters-except-letters-and-numbers-in-php

How to send POST request to another website from a PHP script

Let’s say we have a website like somewebsite.com and there is an input form, but we don’t want to submit that form from that website, instead we send POST request to that page from another website. Here is a handy PHP script to do so:

<?php

$url = 'https://somewebsite.com/';
$data = array('key1' => 'value1', 'key2' => 'vaue2');

$options = array(
    'http' => array(
        'header'  => "Content-type: application/x-www-form-urlencoded\r\n",
        'method'  => 'POST',
        'content' => http_build_query($data)
    )
);
$context  = stream_context_create($options);
$result = file_get_contents($url, false, $context);
if ($result === FALSE) { /* Handle error */ }

var_dump($result);

?>

How to resize QR Code image generated by phpqrcode library

In this tutorial I will show you how to modify the phpqrcode library to generate more bigger and larger QR Code image.

By default if we generate a QR Code of short text or string, we will get a small QR Code image approximately less than 100 pixels. But we can multiply by any number we like.