Article describe database table design and appropriate parts of index.php responsible for subsribtion of user into a mailinglist.
Before preparation of php code for our subscribtion page, we must do some consideration about data that will by stored from users subsribing into mailinglist.
Establishment of database table
In our mailinglist database table will hold ifo about:
first name of subscriber
lastname of subscriber
current date of subscribtion (now() function produce current timestamp)
e-mail of subcriber – UNIQUE value allowed only!!
GDPR true/ flase hold in tiny INT filed
Newsletter subscribed info – true/false hold in tiny INT field
ID
Next picture shows structure of table mailinglist in PHPmyadmin
For simplified perparation of database table is prepared creational script createdatabase.php with content:
Main sript is located on upper part of index.php page. This code is responsible for obtaining POST submitted data (self submission). Next make validation and injection preventing by simple htmlspecialchar(). Only valid e-mails can pass to next stage.
Next parts make solution for database subscriber inserting, deletion of current unwanted subscriber (at time of current opened subsribe form, user can make quick remove decision).
If user will remove next time, must contact admin or in future code will by expaned about separate page for removing by e-mail but without listening table of currently subscribed user (GDPR data lost prevention). But keep in mind our apps are only for demonstration, before proper ussage must be security hardened in a much deeper way (use it on your own risk).
<?php
// two variables for message and styling of the mesage with bootstrap
$msg = “;
$msgClass = “;
// default values of auxiliary variables
$email = „“;
$firstname = „“;
$lastname = „“;
$gdpr = ‚0‘;
$newsletter = ‚0‘;
$is_result = false; //before hitting submit button no result is available
// Control if data was submitted
if(filter_has_var(INPUT_POST, ‚submit‘)){
// Data obtained from $_postmessage are assigned to local variables
We inform you that we use cookies and other technologies on this site to function and improve the operation of the site, ensure it, provide social networking features, personalize content and ads to users, and analyze traffic and user behavior. For more information, please read our Terms of Use and Cookies. You can prevent cookies from being processed by changing the settings in your Internet browser.OkPrivacy policy