how can i make a PHP that shows on a limited number of views

I’m looking for a code that runs a php code in a different time of views, example i have this code

<?php 
echo "Hello world!"; 
?>

now all i need to do is how to make this code open only to 100 or 200 first unique users ? and others just make them see blank page after 200 first opens.. I mean to be more specific run that page 200 times 200 unique users and 201 or 202….. and others see blank page!
If you help me do this project you will make my day! Thanks..!

Advertisements

Exclamation mark difference

What is the difference between using an exclamation mark before a variable in a if statement and inside an equal sign?

before a variable:

if(!$a == $b) {
 //do something
}

inside an equal sign:

if($a != $b) {
 //do something
}

notice that in one example it is !$a and in the other example it is != $b, is there a difference?

Return the date to be more readable in PHP

I would like to convert a date like this 2018-06-30 to something more readable like Vendredi 29 Juin 2018.

So this is what I use:

$date = '2018-06-29';
$jour = array("Dimanche","Lundi","Mardi","Mercredi","Jeudi","Vendredi","Samedi"); 

$mois = array("","Janvier","Février","Mars","Avril","Mai","Juin","Juillet","Août","Septembre","Octobre","Novembre","Décembre"); 

echo $jour[date("w")]." ".date("d")." ".$mois[date("n")]." ".date("Y");

But it returns me the current actual date.

What I missing here please ?

Thanks.


I know I can use setlocale(LC_TIME, 'fr','fr_FR','fr_FR@euro','fr_FR.utf8','fr-FR','fra'); for his case, but actually I dont’ want to use it.

Submit Contact Form Default Text In Text Box

Building a contact form. I have required input fields Your Name, E-mail and phone. Person has to enter information in these fields or else they will get error message. My fourth field is a message text box. In that field using placeholder= I have a default message I am interested in: “get_the_title (of the post)”. Working as I hoped. My problem is I do not want to force person filling form to have to input text in this field and if they don’t add any additional text in the message text box it will send the contact form email with the default text I put there using the “placeholder” text I default generated as mentioned above. Right now my code is forcing text to be input in the message box to send.

enter image description here

Here is the code I am using:

echo '<form action="' . esc_url( $_SERVER['REQUEST_URI'] ) . '" method="post">';
                                echo '<h5>';
                                echo 'Ask a question <br/>';
                                echo '</h5>';
                                echo '<p>';
                                echo '<input style="margin-left: 15px;" type="text" placeholder="Your Name (required)" name="cf-name" pattern="[a-zA-Z0-9 ]+" value="' . ( isset( $_POST["cf-name"] ) ? esc_attr( $_POST["cf-name"] ) : '' ) . '" size="29" />';
                                echo '</p>';
                                echo '<p>';
                                echo '<input style="margin-left: 15px;" type="email" placeholder="E-mail (required)" name="cf-email" value="' . ( isset( $_POST["cf-email"] ) ? esc_attr( $_POST["cf-email"] ) : '' ) . '" size="29" />';
                                echo '</p>';
                                echo '<p>';
                                echo '<input style="margin-left: 15px;" type="text" placeholder="Phone (required)" name="cf-subject" pattern="[0-9-() ]+" value="' . ( isset( $_POST["cf-subject"] ) ? esc_attr( $_POST["cf-subject"] ) : '' ) . '" size="29" />';
                                echo '</p>';
                                echo '<p>';
                                echo '<textarea style="margin-left: 15px; width: 246px;" rows="3" cols="28" placeholder="I am interested in: '.get_the_title().' " name="cf-message">' . ( isset( $_POST["cf-message"] ) ? esc_attr( $_POST["cf-message"] ) : '' ) . '</textarea>';
                                echo '</p>';
                                echo '<p><input type="submit" name="cf-submitted" value="Contact Agent" style="border-radius: 5px; color: #fff; margin-left: 15px; width: 247px; height: 38px; background-color: #27ae60;"></p>';
                                echo '</form>';
                                echo '<p style="font-size: x-small; font-weight: bold; margin-left: 22px;">';
                                echo 'By sending a request you agree to our Privacy Policy';
                                echo '</p>';


                                // if the submit button is clicked, send the email
                                if ( isset( $_POST['cf-submitted'] ) ) {

                                    // sanitize form values
                                    $name    = sanitize_text_field( $_POST["cf-name"] );
                                    $email   = sanitize_email( $_POST["cf-email"] );
                                    $subject = sanitize_text_field( $_POST["cf-subject"] );
                                    $message = esc_textarea( $_POST["cf-message"] );

                                    // get the blog administrator's email address
                                    $to = get_option( 'admin_email' );

                                    $headers = "From: $name <$email>" . "\r\n";

                                    // If email has been process for sending, display a success message
                                    if ( wp_mail( $to, $subject, $message, $headers ) ) {
                                    echo '
'; echo '
Thanks for contacting us, expect a response soon.
'; echo '
'; } else { echo '<h5>An unexpected error occurred.</h5>'; } }

Line Chart – Set data to the existing current point label in Line-chart

So I have a line-chart diagram that consists of four lines with data, on the xAxes I have a set of dates that is from the current date up to 180 days back that I’ve set dynamically with JavaScript.
What I really have to do is take the certain data from the database which I’m doing with the symfony and set it to the
Line-chart lines so far everything is easy.

So the problem is that this data I should take together with
the dates of which are created from the database and set it them to the relevant dates in the Line-chart.So my question is
how to set the current data to the relevant dates in line-chart.P.S I can’t set the date from database as lables directly becuase not all
of this period of 180 days has created data in database and for that I should set the dates dinamicaly with javascript and check if on current date on Line-cahrt has created data from database or not and if it have to set it?

So this is the code from the controller which return the current data:

   // get all sent letters from current reseller
    $sql = "select count(Distinct d.id) as letter from document d  left join printjob pj on pj.id = d.printjob_id  join partner on partner.id = d.partner_id where pj.sent_at is not null and d.error_at is null and d.deleted_at is null and pj.error_at is null and d.customer_id = :customer_id  and d.partner_id = :partner_id and pj.sent_at BETWEEN DATE_SUB(DATE(NOW()), INTERVAL 180 DAY) AND DATE(NOW()) GROUP BY pj.sent_at";
    $stmt = $em->getConnection()->prepare($sql);
    $stmt->bindValue("customer_id", $this->getUser()->getCustomer()->getId());
    $stmt->bindValue("partner_id", $this->getUser()->getPartner()->getId());
    $stmt->execute();
    $result = $stmt->fetchAll();
    $status['sentLetterByReseller'] = $result[0]['letter'];

    // get all sent letters from current sub-reseller
    $sql = "select count(Distinct d.id) as letter from document d  left join printjob pj on pj.id = d.printjob_id  join partner on partner.parent_partner_id = d.partner_id where pj.sent_at is not null and d.error_at is null and d.deleted_at is null and pj.error_at is null and d.customer_id = :customer_id  and d.partner_id = :partner_id and pj.sent_at BETWEEN DATE_SUB(DATE(NOW()), INTERVAL 180 DAY) AND DATE(NOW()) GROUP BY pj.sent_at";
    $stmt = $em->getConnection()->prepare($sql);
    $stmt->bindValue('customer_id', $this->getUser()->getCustomer()->getId());
    $stmt->bindValue("partner_id", $this->getUser()->getPartner()->getId());
    $stmt->execute();
    $result = $stmt->fetchAll();
    $status['sentLetterBySubReseller'] = $result[0]['letter'];

    // get all sent pages from current reseller
    $sql = "select  sum(COALESCE(numpages,0)) as pages from document d left join printjob pj on pj.id = d.printjob_id join partner on partner.id = d.partner_id where pj.sent_at is not null and d.error_at is null and d.deleted_at is null and pj.error_at is null and d.customer_id = :customer_id and d.partner_id  = :partner_id  and pj.sent_at BETWEEN DATE_SUB(DATE(NOW()), INTERVAL 180 DAY) AND DATE(NOW()) GROUP BY pj.sent_at";
    $stmt = $em->getConnection()->prepare($sql);
    $stmt->bindValue('customer_id', $this->getUser()->getCustomer()->getId());
    $stmt->bindValue("partner_id", $this->getUser()->getPartner()->getId());
    $stmt->execute();
    $result = $stmt->fetchAll();
    $status['sentPagesByReseller'] = $result[0]['pages'];

    // get all sent pages from sub-reseller
    $sql = "select  sum(COALESCE(numpages,0)) as pages from document d left join printjob pj on pj.id = d.printjob_id join partner on partner.parent_partner_id = d.partner_id where pj.sent_at is not null and d.error_at is null and d.deleted_at is null and pj.error_at is null and d.customer_id = :customer_id and d.partner_id  = :partner_id  and pj.sent_at BETWEEN DATE_SUB(DATE(NOW()), INTERVAL 180 DAY) AND DATE(NOW()) GROUP BY date(pj.sent_at)";
    $stmt = $em->getConnection()->prepare($sql);
    $stmt->bindValue('customer_id', $this->getUser()->getCustomer()->getId());
    $stmt->bindValue("partner_id", $this->getUser()->getPartner()->getId());
    $stmt->execute();
    $result = $stmt->fetchAll();
    $status['sentPagesBySubReseller'] = $result[0]['pages'];

This is the code from line-chart:

    let start = moment();
    let end = moment().subtract(180 , 'd');
    let arrLableDates = [];
    let lastDay = moment().toISOString().slice(0,10);

    let tmp = end.clone().day(1);

    if( tmp.isAfter(start, 'd') ){
        arrLableDates.push(tmp.format('YYYY-MM-DD'));
    }
    while( tmp.isBefore(start) ){
         tmp.add(1, 'days');
        arrLableDates.push(tmp.format('YYYY-MM-DD'));
    }

    arrLableDates.push(lastDay);

// LIne chart production volume diagram
    var ctx = document.getElementById("Production-volume-chart");
    ctx.height = 350;
    var chart = new Chart(ctx, {
        type: 'line',
        responsive: true,
        data:
    {
            labels: arrLableDates,
            datasets: [{
                label: "Sent letters by reseller",
                backgroundColor: 'rgb(255, 99, 132)',
                data: status.sentLetterByReseller ,
                fill: false
            }
            ,{
                data: status.sentLetterBySubReseller,
                label: "sent letters by sub-reseller",
                borderColor: "#8e5ea2",
                fill: false
            }, {
                data: status.sentPagesByReseller,
                label: "Sent pages by reseller",
                borderColor: "#e8c3b9",
                fill: false
                }, {
                data: [enter image description here][1]status.sentPagesBySubReseller,
                label: "Sent pages by sub-reseller",
                borderColor: "#c45850",
                fill: false
            }
            ]
        },

        // Configuration options go here
        options: {            
            elements: { point: { radius: 0 } },
            maintainAspectRatio: false,
            scales: {
                xAxes: [{
                    ticks: {
                        // minRotation: 90,
                        autoSkip: true,
                        maxTicksLimit: 15,
                        beginAtZero:true
                    }
                }],
                yAxes: [{
                    ticks: {
                        beginAtZero:true
                    }
                }],
            }
        }
    });

This is an example of how the chart should looks like

Line-chart

I will be glad if someone has a suggestion how to solve this problem.

Best regards Georgi!

update.php not returning errors, but no updates to database

I have checked similar questions to this on here and tried some solutions, but I cannot get it to work. I am newer to php and cannot figure out what the problem is since no errors are returned.

It has be be a simple error, but I cannot find it. Here is my update.php and the first answer below is my updateform.php.

<?php
session_start();
//check the session
if (!isset($_SESSION['email'])){

exit();
}else{
//include the header
include ("../includes/header.php");
require_once ('../includes/mysqli_connect.php');

#execute UPDATE statement
$id = mysqli_real_escape_string($dbc, $_POST['emp_id']); 
$fname = mysqli_real_escape_string($dbc,  
$_POST['first_name']); 
$lname = mysqli_real_escape_string($dbc, 
$_POST['last_name']); 
$ad = mysqli_real_escape_string($dbc, $_POST['address']); 
$ci = mysqli_real_escape_string($dbc, $_POST['city']); 
$st = mysqli_real_escape_string($dbc, $_POST['state']); 
$zip = mysqli_real_escape_string($dbc, $_POST['zipcode']); 
$ph = mysqli_real_escape_string($dbc, $_POST['phone']); 
$e = mysqli_real_escape_string($dbc, $_POST['email']); 


$query = "UPDATE employees SET  
first_name='$fname',last_name='$lname',
address='$ad', city='$ci', state='$st', zipcode='$zip', 
phone='$ph', email='$e'  WHERE emp_id='$id'"; 
$result = @mysqli_query ($dbc, $query); 
if ($result){
    echo "<center><p><b>The member account has been updated.
</b></p>"; 
    echo "<a href=index.php>Home</a></center>"; 
}else {
    echo "<p>The record could not be updated due to a system 
error" . mysqli_connect_error() . "</p>"; 
}
mysqli_close($dbc);
//include the footer
include ("../includes/footer.php");
}

?>