PHP + MySQL + jQuery =

I developed as a side project using data from the Weekly Oil Bulletin provided every week(or almost) by the European Commission. PHP and MySQL helped me with the back site work and chart.js helped me a lot with the chart and data representation of the Diesel and Euro-Super 95 data flows.

The data range is from 2015 inclusive to our present week.

I also have in plan to add to the database all of the data beginning from 2009, that means a lot of PHPmyAdmin work for me in the next future.

For more informations about this project you can contact me.

jQuery toggle both content and button

<script src="//"></script>

<script type="text/javascript">
$( ".sod" ).click(function() {
  $( ".sods" ).toggle(function() {
    $( ".blo" ).toggle("slow");



Display as you type input value in div and input type populate with the same text with jQuery

Some situations need a special way of thinking regarding functionality and automation.

This little script sends the text typed in a form/input type to a div and also to another input type so that you can use in many ways the final result – the POST or GET variable created. Also the fist input type works with its defined name.

You can see a working demo here: DEMO

jQuery add/remove hidden input field to form on click

    type: 'hidden',
    name: 'sms-yes',
    value: 'yes'
console.log('hidden yes added!');

    type: 'hidden',
    name: 'sms-no',
    value: 'no'
console.log('hidden no added/yes removed!');

I used this little code with a reservation form… to put it simple… the user that wanted to make a reservation could opt in/out of receiving a confirmation SMS a few hours before the scheduled date/time…

Real time display input value in div with jQuery

I used this simple trick to display the name of a person after he sends the form data via Ajax and I needed a different response(not from Ajax), so, I set the response message to display:none via css and get the name or other informations in real time… when the form is submitted… the div becomes visible and shows the result… like Thank you {Name} for sending us etc. …

$('#name_x').keyup(function () {

<pre class="wp-block-code"><code>&lt;form&gt;
<form<input type="text" name="name" id="name_x" size="44" 
placeholder="Type here to see real time result in div..." style="padding:12px;border-radius:4px;border:1px solid grey" >
<div id="get_name"></div>

You can see a live demo here.

Send data to PHP via AJAX and get response

This is the simple script that I use every time I build one page sites… I use this code to update, delete, modify, add data to Mysql or other DB’s…

This code also get the class or id of the clicked link and can display a result there or in another div… this script can also be modified to play other important parts in the web app…

Hope it helps.

$('.get-delete').click(function() {
    var get_id = $(this).attr('id');
    $("#" + get_id ).toggle(400);
        type: 'POST',
        url: 'delete.php',
        data: { idx: get_id},
        success: function(response) {

jQuery (Ajax) Contact form with all elements

This is my default CONTACT form built with jQuery and CSS.
The form uses a jQuery call to a PHP script that inserts data into a Mysql DB and sends two emails of confirmation, all this under the hood… meanwhile, there is a CSS only animation that displays a message that the data is been sent to the server and shows a positive message if that data was sent without errors and an error message if there was an error.


var request;



    if (request) {
    var $form = $(this);
    var $inputs = $form.find("input, textarea");
    var serializedData = $form.serialize();
    $inputs.prop("disabled", true);
    request = $.ajax({
        url: "contact-form.php",
        type: "post",
        data: serializedData
    request.done(function (response, textStatus, jqXHR){
        //console.log("Hooray, it worked!");
    }); (jqXHR, textStatus, errorThrown){
            "The following error occurred: "+
            textStatus, errorThrown


    request.always(function () {
        $inputs.prop("disabled", false);


.frm{padding:9px;border-radius: 3px;background:#ECEFF1;font-size: .8em; border:0px; width: 100%;font-weight: 300;box-sizing: border-box;}
.pt-12{padding-top:12px}.small{font-size: .8em}
.org-bg{background:#E74C3C;padding: 12px;border-radius: 3px;margin-bottom: 12px;color: #fff}.grn-bg{background:#52BE80;padding: 12px;border-radius: 3px;margin-bottom: 12px;}


.spinner {
  margin: 0px auto 0;
  width: 70px;
  text-align: center;

.spinner > div {
  width: 18px;
  height: 18px;
  background-color: #333;

  border-radius: 100%;
  display: inline-block;
  -webkit-animation: sk-bouncedelay 1.4s infinite ease-in-out both;
  animation: sk-bouncedelay 1.4s infinite ease-in-out both;

.spinner .bounce1 {
  -webkit-animation-delay: -0.32s;
  animation-delay: -0.32s;

.spinner .bounce2 {
  -webkit-animation-delay: -0.16s;
  animation-delay: -0.16s;

@-webkit-keyframes sk-bouncedelay {
  0%, 80%, 100% { -webkit-transform: scale(0) }
  40% { -webkit-transform: scale(1.0) }

@keyframes sk-bouncedelay {
  0%, 80%, 100% { 
    -webkit-transform: scale(0);
    transform: scale(0);
  } 40% { 
    -webkit-transform: scale(1.0);
    transform: scale(1.0);

.trimit{background: rgba(149, 192, 234);padding: 12px; border-radius: 3px;margin-top:12px;font-family:'Quicksand',sans-serif;font-weight:400;font-size:.8em;}
<!-- form ROW -->
<div class="row pt-12x">

<div id="loading">
<div class="spinner">
  <div class="bounce1"></div>
  <div class="bounce2"></div>
  <div class="bounce3"></div>

<div class="trimit"><i class="far fa-paper-plane fa-fw"></i> Se trimit datele...</div>


<!-- Error Handlers --><div id="show-success"></div>
<div class="grn-bg orange-bg list-font-1 hide show-success"><i class="fas fa-check-square fa-fw"></i> <b>Vă mulțumim!</b> Am primit mesajul dumneavoastră.</div>
<div class="org-bg orange-bg list-font-1 hide show-error"><i class="far fa-question-circle fa-fw"></i> <b>Eroare!</b> Mesajul nu a fost trimis.</div>
<!-- .Error Handlers -->
<!-- form --> <form id="contact-form">                        
  <div class="hide-contact">
<div class="fc"><i class="fas fa-user fa-fw brown"></i> Formular contact</div>

              <input type="text" name="name" class="frm" placeholder="Nume" required="">
            <div class="pt-12">
              <input type="text" name="email" class="frm" placeholder="" required="">

            <div class="pt-12">
              <input type="text" name="phone" class="frm" placeholder="Număr telefon" required="">

            <div class="pt-12">
              <textarea name="message" class="frm" rows="6" placeholder="Mesaj..."></textarea><input type="text" name="city" value="" class="hide">


<div class="pt-12 small"><i class="fas fa-lock fa-fw green"></i> Protecția datelor <small>(GDPR) (EU) 2016/679 <a href=""><i class="fas fa-external-link-alt fa-fw"></i></a></small></div>

            <div class="pt-12">
              <button type="submit" class="frm frb dsblb"><i class="fas fa-paper-plane fa-fw"></i> Trimite</button>

</div> <!-- ./hide-contact -->

<!-- ./form-ROW -->


// v1.0 090318

if(isset($_POST['city']) && !empty($_POST['city'])) {

echo "Hello Robot!";



if(empty($_POST['name']) || empty($_POST['email']) || empty($_POST['message'])) {

echo "Hello Robot 2!";



$today = date("d/m/Y - G:i ");



// _POST Vars...

$name     		= htmlentities($_POST['name']);
$email    		= htmlentities($_POST['email']);
$phone    		= htmlentities($_POST['phone']);

$message1  		= htmlentities($_POST['message']);

$data 			= time(); 

$sql = "INSERT INTO table_name
(name, email, phone, message, data)
('$name', '$email', '$phone', '$message1', '$data')";

if ($conn->query($sql) === TRUE) {




// yeyy! Mail to owner...

$to_owner = "";
$subject_owner = "New message from...";

$message_owner = "
<title>New message</title>
<p><h3>Mesaj nou pe site...</h3></p>
<p>Detalii mesaj:</p>
<li>Name: $name</li>
<li>Phone: <a href=\"tel:$phone\">$phone</a></li>
<li>Email: $email</li>
<li>Data: $today</li>
<li>Message: $message1</li>

// Always set content-type when sending HTML email
$headers_owner = "MIME-Version: 1.0" . "\r\n";
$headers_owner .= "Content-type:text/html;charset=UTF-8" . "\r\n";

// More headers
$headers_owner .= 'From: Name<contact@example>' . "\r\n" . "Reply-to: $email" . "\r\n";
$headers_owner .= 'Cc:' . "\r\n";

mail($to_owner, $subject_owner, $message_owner, $headers_owner);

/// +++++++++++++++++++++ /////


} else {
    echo "Error: " . $sql . "<br>" . $conn->error;


jQuery + CSS – Activate DIV background colour and deactivate other DIV’s bg colour

This little code delivers all the magic, if you are into one page websites/apps like me, this short code will simply save you lots of time.
This code simply activates(changes the style) of an DIV that is clicked on and removes the same style applied to other DIV(active button) in case it has another active style applied to another DIV.
It can be combined with a little CSS code to display a beautiful color transition.
You can see the code running on this little jsFiddle I made:

$(document).ready(function() {

	$('body').on('click', '.section-white', function() {

	background-color: #82E0AA;
    -webkit-transition: background-color 1000ms linear;
    -ms-transition: background-color 1000ms linear;
    transition: background-color 1000ms linear;

jQuery load() external file inside div

Sometimes I use the jQuery load() function to display dynamic content inside html elements. As the description says:

load() Description: Load data from the server and place the returned HTML into the matched element.

I provided a working example that loads a simple html file with html tags and another php files that contains variables.

Here is the jQuery code:

$(document).ready(function() {

 $(".click-html").on('click', function() {
  $( ".load-html" ).load( "load.html" );

 $(".click-php").on('click', function() {


Here is the PHP code that deals with the two variables:

echo $_GET["var1"];
echo "<br>";
echo $_GET["var2"];
if($_GET["var2"] == "var2value") {
echo "<hr>";

Live Demo Here