PHP is a widely-used server-side scripting language especially suited for web development, powering tens of millions of sites from Facebook to personal WordPress blogs. PHP is often paired with the MySQL relational database, but includes support for most other mainstream databases. By utilizing different Server APIs, PHP can work on many different web servers as a server-side scripting language.

Share tech news, updates, or what's on your mind.

Sign up to Post

Hello, I am attempting to set the class of a <li> using a PHP if statement. The goal is to highlight the name of the person currently logged in. However the class is being set for all users and I cannot figure out why. Here is the code snippet:
	while ($row = mysql_fetch_array($leaders)) {?>
					 <li class ="<?php if($row["UserID"] = '$user_id'){echo 'leaderboard__user-highlight';} ?>"><div class="leader__wrap">
							<div class="course-list__item--details"><h6><?php echo $row["FName"] ?> <?php echo $row["LName"] ?> </h6>
								<p><?php echo $row["User_points"] ?></p>
							<h5 class="user__badge  badge--expert">Expert</h5>
					<?php } ?>

Open in new window

I have verified that the $user_id is correct for the user that is logged in and that each line item does have a different UserID, what am I missing here? Thanks.
Angular Fundamentals
LVL 12
Angular Fundamentals

Learn the fundamentals of Angular 2, a JavaScript framework for developing dynamic single page applications.

How to generate CSV file and send an email as an attachment of that csv file in laravel?
Hi Experts,

I'm expiriencing one of the strangest issues.

I have the following PHP Code

function ins_checkboxes($name, &$chk_array){
    $code = '';
    $lbl = '';
    $type = '';
    $onclick = '';
    foreach ($chk_array as $chk):
        $code = $chk['code'];
        $lbl = $chk['lbl'];
        $type = $chk['type'];
        $onclick = '';
        $div_specify = '';
        echo "code = $code <br />";
        if ($type == 'chk+txt') {
            $div_specify = "divSpecify-" . $code;
            $onclick = 'onchange="show_hide(\'' . $div_specify . '\');"';
        echo "code = $code <br />";
    <div class="divChecks">
        <input type="checkbox" name="<?php echo $name; ?>[]" 
               id="chk<?php echo $code; ?>" value="<?php echo $lbl; ?>" 
                   <?php echo $onclick; ?> >
        <label for="chk<?php echo $code; ?>"><?php echo $lbl; ?></label>
    echo "code = $code <br />";
    if ($type == 'chk+txt'){
        <div id="<?php echo $div_specify; ?>" class="divNoDisplay">

            <label for="txt<?php echo $code; ?>">Please Specify</label>
            <input type="text" id="txt<?php echo $code; ?>" name="txt<?php echo $code; ?>">



Open in new window

Thee resulting HTML of the first 2 loops iss
        code = strQ5Cert_Drive <br>code = strQ5Cert_Drive <br>    
    <div class="divChecks">
        <input type="checkbox" name="strQ5Certs[]" id="Driver's Licence" value="Driver's Licence">
        <label for="Driver's Licence">Driver's Licence</label>
    code = strQ5Cert_Drive <br>code = strQ5Cert_Health <br>code = strQ5Cert_Health <br>    
    <div class="divChecks">
        <input type="checkbox" name="strQ5Certs[]" id="Health &amp; Safety Representative" value="Health &amp; Safety Representative">
        <label for="Health &amp; Safety Representative">Health &amp; Safety Representative</label>
    code = strQ5Cert_Health <br>

Open in new window

You will note that I'm echo-ing my $code variable twice before my <input> and <label> tags, and once after.

In the first instance, $code = strQ5Cert_Drive, which is correct. However, when I use $code for my <label for=> and  <input id=>, you will see thhat the output  is different ... its that of $lbl.

Its been a long day, maybe I'm tired... How can this be?

Any help will be appreciated,
i have page to add new package with inputs and i have multi row dynamic create row for more details to this package inside this page

and also i have multi image uploader the same idea for invoice but add to this multi images

i have this photos to help you think my case

<?php include "header.php"; ?>      

			/// validate vars
			$num=" SELECT MAX( package_id ) as package_id FROM packages ";
				$row = mysqli_fetch_array($query);
					$max= $row['package_id'];
					if($max > 500){
						$package_id= $max + 1 ;
						$first= 500 ;
						$package_id= $max + 501 ;

		<script src="../tinymce/tinymce.min.js"></script>
			selector: '.mytextarea'
      <!-- Right side column. Contains the navbar and content of the page -->
      <div class="content-wrapper">
        <!-- Content Header (Page header) -->
        <section class="content-header">
            <small>Control panel</small>

        <!-- Main content -->
        <section class="content">
          <!-- Main row -->
          <div class="row">
            <!-- Left col -->
            <section class="col-lg-12 connectedSortable">

              <!-- quick email widget -->

Open in new window

I'm attempting to pass an XML file

    $xml = simplexml_load_file('test.xml');

Open in new window


  public 'title' => string "My Title" (length=8)
public  'properties ' =>
           array (size=1234)

Open in new window

Before some one asks I cannot upload the xml file but it looks like this (There might be errors due to fat fingers)

<?xml version="1.0" encoding="UTF-8" ?>
<resultset  xmlns="" xmlns:ns2="" xmlns:ns2="">
  <title>The Searchers</title>
  <properties >
    <ns2:value  xmlns:xs=""  xsi:type="xs:string">As a Civil War veteran spends years searching for a young niece captured by Indians, his motivation becomes increasingly questionable.</ns2:value>
  </properties >
  <properties >
    <ns2:value  xmlns:xs=""  xsi:type="xs:string">John Ford</ns2:value>
  </properties >
  <properties >
    <ns2:value xmlns:xsi="" xsi:type="ns2:list">

Open in new window

Hi expert ,  I count the period of start date and today date and by loop insert into the database , but problem is when i insert already the period and when i on the next month so how the new month was insert into . Any solution for tis case?

I also encounter with the problem of total if the payment not paid , the fine will added 10% into total , so the total should be 500 (first month) , 550 (second month) and 600 (third month) insert with the loop.

	$start = (new DateTime($sdate))->modify('first day of this month');
	$today = date("Y-m-d");
	$end      = (new DateTime($today))->modify('first day of next month');
	$interval = DateInterval::createFromDateString('1 month');
	$period   = new DatePeriod($start, $interval, $end); 
	foreach($period as $dt){
	$date = $dt->format("M Y");
	$invoice_sum = $service + $sink + $fire + $quit + $ass; 
	$total_payment = $invoice_sum + $late_payment - $paidfee;
	$query3 = "INSERT INTO owner_monthlyfees (`owner`,`unit_name`,`date`,`invoice_sum`,`payment`,`late_payment_charges`,`total`) VALUES ('$owner','$unit','$date','$invoice_sum','$paidfee','$late_payment','$total_payment')";

Open in new window

I've been able to successfully incorporate a Singleton class into my app and am now using that to establish my database connection.

But while it's working, I want to know WHY it works. Below is a breakdown of what I understand combined with some questions. If you could "fill in the gaps," that would be awesome!

First of all, I'm going to use the Scople Resolution Operator to call what I know to be a static method from the "DB" class tht is also protected...

$display_page=DB::query("SELECT * from employers where id=?", [$id]);

Open in new window

Here's the private static function that's beeing called:

private static function query($statement, $bindParams=NULL, $assoc=NULL)

Open in new window

 Because its private, the, __callStatic method is going to be called which looks like this:
public static function __callStatic($name, $args=NULL){
            // connect here

			self::$conn = new PDO("mysql:dbname=adsf; host=adsf", "adsf", 'adsf');
			self::$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
        return call_user_func_array('self::'.$name, $args);

Open in new window

But here's where I'm getting confused.

If I understand things correctly, "$name, $args=NULL" is my query ("SELECT * from employers were id=?") and my [$id], correct?

...and then when you get to return call_user_func_array('self::'.$name, $args), 'self::'.$name is my $statement and the $args is my [$id'] value.

So how does $conn get included / implemented?

From what I understand, __calStatic is going to be called automatically when "private static function query" is called. I see how the "($name, $args=NULL)" dynamic places those two entities in a spot where they can be acted upon, but how does $conn get established?

Trying to send checkbox state to PHP page using Ajax. I am able to send he value of the element but I also need to send the state of the button that will determine if the data is added or deleted from the database. Here is what I have.

 $(document).on('click', '.favorite-resource-checkbox', function(){  
            var resourceValues = $( this ).val();
		    var user = "<?php echo $user_id; ?>";
	 		var id = $(this).attr('id');
                data:{value: resourceValues , user: user},  

Open in new window

Ok my problem,

I used ajax with case statements on php end.

function saveAct(){
    var testAct = $('#act-data :input').serialize();
           type: "POST",
           url: 'controllers/contacts.ajax.php',
           data: { subaction : "saveActDetails" , actForm : testAct},
           dataType: "json" 
        }).success(function (response) {
        }).error(function (response) {
               console.log(" save-act error");

Open in new window

so i use the post type,  i use the subaction to trigger the correct case, then im using the actFrom to send form data, now i want to be able to use this data to insert into a table. but im first seeing what i am posting, the return looks a match to the form however i dont think i can use it and add this to a table.

case 'saveActDetails' :

		$response = array(
			'Result' => 'save-act success',
			'data' => $_POST['actForm']


Open in new window

any solutions ?
Dear Experts,

I need to write below the below code in PHP, how can I get the screen resolution in PHP ?

   <script type="text/javascript">
 if (screen.width >= 950) {
  window.location = "";

Open in new window

Fundamentals of JavaScript
LVL 12
Fundamentals of JavaScript

Learn the fundamentals of the popular programming language JavaScript so that you can explore the realm of web development.

I am using the script below to verify that the user enters the correct information on a registration page. Everything works FINE per individual field, and it displays an error message if there was an error entering the field information. The problem is that there are 5 different INPUT FIELDS, and the user might enter 3 correct and 2 incorrect, BUT IF THE USER GOES BACK AND CORRECT 1 FIELD (OF THE PREVIOUSLY 2 INCORRECT), and then submit the form THE FORM IS SUBMITTED WITH 1 FIELD ERROR.  How can I solve this issue NOT TO BE ABLE TO SUBMIT FORM IF AN ERROR ON FORM

Tnx, I have been trying to figure this for 5 days already :-(
I thought of a hidden field with value 0 for correct or 1 for incorrect, but that wouldn't solve the problem according to my previous example

I am using HTML and an external PHP to verify values

<script type="text/javascript">
    function ajaxFunction(disp_div) {
        var httpxml;
        try {
            // Firefox, Opera 8.0+, Safari
            httpxml = new XMLHttpRequest();
        } catch (e) {
            // Internet Explorer
            try {
                httpxml = new ActiveXObject("Msxml2.XMLHTTP");
            } catch (e) {
                try {
                    httpxml = new ActiveXObject("Microsoft.XMLHTTP");
                } catch (e) {
                    alert("Your browser does not support AJAX!");
                    return false;

        function stateChanged() {

Open in new window

I have an application built using php/mariadb

i want to create a demo of the site that has standard data in it. A user can then play around with the data.

I do not want the new data entered by the demo user to exist for another user

what are my opions?

I am using Google Maps API version 2.

I need to cusztomize the Google map zoom effect as in this below video:

Open in new window

Any help will be greatly appreciated.

Note: The zoom effect will be visible when user selects a country name from a select box.

Wordpress - Themes and Child themes

OK Ive got a Wordpress site that has a theme, and at some time in the past Ive created a child theme and made some changes, all good
BUT, before I knew what I was doing, I made some direct edits on files in the parent theme.

Now I've compared the live sites theme with the original factory default, and the files that have changed are....


So, my question is, If I coped those file to the Themename-Child directory, I should be able to update the theme without anything smashing correct?

The problem is compounded, as in the child theme I also have a functions.php and a header.php file?

From what I've read it's probably using the header.php from the child theme anyway?
But Ive also read that functions.php loads the child and the parent, so Im not sure what to do about that one?



I am attending a few of the many online PHP education courses right now, and here I have got a little challenge.

I have made this "send e-mail" form, and I am trying to create two message pop-up's to give message if the message is sent or if there is missing something to be filled in the form.
For education purposes I would very much like to make this in PHP, and it here I am getting in trouble.

With the code below, I get the right message with a green background if all fields in the form is filled out before submitting, but when I miss to fill one ore more fields in the form it displays the red background with the right message in it, but the problem is that it also displays the green box - now empty - and places it below the red one.

If anybody can give me a hint how to get the green box to disappear when all fields not are filled I would be very grateful :)

<form class="" action="index.php" method="post" style="width: 150px; margin-left: 8px; "> 
  <h3>Send e-mail</h3>
  <input type="text" name="to" value="" placeholder ="Til"><br><br>
  <input type="text" name="subject" value="" placeholder="Emne"><br><br>
  <textarea rows="10" cols="30" name="message" placeholder="Besked"></textarea><br><br>
  <input type="submit" name="" value="Send besked" style="margin-left: 50px; ">

  ini_set('display_errors', 1);

<div class="mailmessage" style ="background: #ff3300; color: #fff; font-weight: bold; width: 

Open in new window

I am reading image files from a folder and save the results in the database. There are multiple duplicate images in a folder (same image but different filename).
I am getting md5 of a file to marked the file as duplicate.

While saving the records in database how I can ignore the duplicate files to not save in Database.

This is my code:


require_once 'db.php';

$dir = '../../../../../sites/default/files/';

$exts = array('gif', 'jpg', 'jpeg', 'png');

if ( is_dir($dir) ):

    // Set up the Iterator
	$directory = new RecursiveDirectoryIterator($dir, FilesystemIterator::SKIP_DOTS); //skip dots and double dots hidden folders
    $iterator = new RecursiveIteratorIterator($directory);

    // Clear the table
    $conn->query("TRUNCATE TABLE searchindex_images");
    // Prepare the INSERT query   
	$insert = $conn->prepare("INSERT INTO searchindex_images (dir, img_names, lang,file_date) VALUES (? , ? , ? , ?)");
	$insert->bind_param("ssss", $path, $img, $language,$myhash);   	
$foldersToSkip = ['css','default_images','docs'];

foreach ($iterator as $file):
    $folders = explode( DIRECTORY_SEPARATOR, $file->getPath() ); // split the path into an array.	

    if ( ! empty( array_intersect($foldersToSkip, $folders) ) ) { // see if any folder is matched with $foldersToSkip
        // let's skip this folder
		print "<br>Folder SKipped";
			//// This code only works on Linux OS. It checks for arabic characters in

Open in new window

Wordpress Pagination
I've built a website related to crypto-currency . I am using coinmarketcap professional API for building a page which shows all cryptocurrency live data. For that i have a code for paginaitoh in php (File-). The code works successfully when run via Xampp (localhost), I get the required data-()
But when the same code is uploaded to wordpress page, it fails to work ( live data doesn't show up )-().
Hope any expert help me get through this. Thanks.
Redis Cache.
I am using a Redis Cache plugin on a WordPress / WooCommerce website.  There is some custom functionality that happens when a product is duplicated.  A unique UPC code is automatically issued to the new product.  What seems to be happening is that the result of the query ends up being cached and the same UPC code gets issued to each product duplicated.  When I turn off the cache the problem goes away.  The question is, is there a way to keep a specific function/query results from being cached by the Redis functionality.
This is the plugin:
Needless to say, this is above my pay grade.
PHP - two separate forms on two pages. I want to combine them into one form on one page.

Form No. 1 - uploading three images -

<form enctype="multipart/form-data" action="add_file2.php" method="post">

	<fieldset><legend>Fill out the form to upload a file:</legend>
    <input type="hidden" name="MAX_FILE_SIZE" value="524288">
	<?php // Create the inputs.
	for ($i = 0; $i < $counter; $i++) {
		echo '<p><b>File:</b> <input type="file" name="upload' . $i . '" /></p>';
    <input type="hidden" name="submitted" value="TRUE" />
    //<div align="center"><input type="submit" name="submit" value="Submit" /></div>

Open in new window

Form No 2. - general information

    <form action="PostANoticeYE.php" method="POST" accept-charset="utf-8">
         <p><label for="description" class="SmallHeading"><strong>Description</strong></label>
Please enter a brief description. You have up to 300 characters.
      <div id="div1">Characters Left = 300</div>
<?php create_form_input('description', "textarea", $PostANoticeYE_errors,"maxlength='300' onkeyup='return chlimit(this)' "); ?>

<br />

		<label for="amount" class="SmallHeading"><strong>Amount</strong></label>
        <p class="noticeType">Less than 20 characters please.
		<?php create_form_input('amount', 'text', $PostANoticeYE_errors); ?><br />

		<label for="currency" class="SmallHeading"><strong>Currency</strong></label>
        <p class="noticeType">Enter the currency that you used to

Open in new window

Microsoft Azure 2017
LVL 12
Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

I am using 3rd party Search and I have more than 1000 HTML pages. The full HTML content is saved in database in separate rows.
In search results I display the page title from a Db field and some HTML content of 200 words. Everything works fine.

The Problem:
Some HTML pages (stored in db) have inline CSS and JS code like below:

<div class="content">
    <div class="field field-name-body field-label-hidden"><div class="field-items"><div class="field-item even"><style>
                        #dropBox {
                          border: 3px dashed #0087F7;
                          border-radius: 5px;
                          background: #F3F4F5;
                          cursor: pointer;

                        #dropBox {
                          min-height: 150px;
                          padding: 54px 54px;
                          box-sizing: border-box;

                        #dropBox p {
                          text-align: center;
                          margin: 2em 0;
                          font-size: 16px;
                          font-weight: bold;

                        #fileInput {
                          display: none;
  <script type="text/javascript">
	 if (jQuery(&#039;#myline-check&#039;).is(":checked")) {

Open in new window

I am running WHMCS software used for billing which is built using PHP & MySQL. Recently we have been receiving some issues when it is accessed through API by our Payment gateway  

Apache access log shows following lines which shows the server got 500 internal server error: - - [13/Sep/2018:10:54:58 +0500] "POST /modules/gateways/callback/tco.php HTTP/1.1" 500 27 "-" "Jakarta Commons-HttpClient/3.1" - - [13/Sep/2018:10:54:59 +0500] "POST /modules/gateways/callback/tco.php HTTP/1.1" 500 27 "-" "Jakarta Commons-HttpClient/3.1" - - [13/Sep/2018:10:54:59 +0500] "POST /modules/gateways/callback/tco.php HTTP/1.1" 500 27 "-" "Jakarta Commons-HttpClient/3.1" - - [13/Sep/2018:10:54:58 +0500] "POST /modules/gateways/callback/tco.php HTTP/1.1" 500 27 "-" "Jakarta Commons-HttpClient/3.1" - - [13/Sep/2018:10:55:00 +0500] "POST /modules/gateways/callback/tco.php HTTP/1.1" 500 27 "-" "Jakarta Commons-HttpClient/3.1" - - [13/Sep/2018:10:54:58 +0500] "POST /modules/gateways/callback/tco.php HTTP/1.1" 500 27 "-" "Jakarta Commons-HttpClient/3.1" - - [13/Sep/2018:10:54:58 +0500] "POST /modules/gateways/callback/tco.php HTTP/1.1" 500 27 "-" "Jakarta Commons-HttpClient/3.1" - - [13/Sep/2018:10:54:58 +0500] "POST /modules/gateways/callback/tco.php HTTP/1.1" 500 27 "-" "Jakarta Commons-HttpClient/3.1" - - [13/Sep/2018:10:54:58 +0500] "POST 

Open in new window

Dear EEs, is there any free software for Linux which can serve similar like Online Office server in Window?

We'd like to edit document online on web browser on OwnCloud.

Many thanks!
Hello Experts!

Is it possible by code to skip the Header (Top Row) in Excel Spreadsheet?
I'm using PHPExcel_Reader to process upload into database.
See attached.
Thank you.

I am attempting to create a page that uploads images and saves them for viewing for members who belong to a website.

The page is posting to itself but not putting anything into the database, not letting the viewer know it has been uploaded OR giving any kind of error message. I took out one of the fields – description – as it is not needed so I am wondering if there is anything in the code that still refers to this field and the rest of the data is just not going into the database to begin with. My database columns are – file_name, file_size, file_type.


require ('./includes/');

require (MYSQL);

$counter = 3; // Number of files to allow for.

if (isset($_POST['submitted'])) { // Handle the form.

	//require_once ('mysql_connect.php'); // Connect to the database.
	for ($i = 0; $i < $counter; $i++) { // Handle each uploaded file.
		// Create index names to refer to the proper upload and description.
		$filename = 'upload';
		// Check for a file.
		if (isset($_FILES[$filename]) && ($_FILES[$filename]['error'] != 4)) {

			// Add the record to the database.
			$query = "INSERT INTO notices (file_name, file_size, file_type) VALUES ('{$_FILES[$filename]['name']}', {$_FILES[$filename]['size']}, '{$_FILES[$filename]['type']}')";
			$result = mysql_query ($query);
			if ($result) {
				// Return the upload_id from the database.
				$upload_id = mysql_insert_id();
				// Move the file over.

Open in new window

Hello Experts!

I'm using PHPExcel_Reader to import data into MySQL. One of the columns in Excel file is Date_Of_Birth.

I've tried many methods to no avail. I'm afraid, google search has not yielded any desirable result either.

In the script, I have:
$date_of_birth = "";
if(isset($Row[4])) {
   $date_of_birth = date('Y-m-d', strtotime($Row[4]));

Open in new window

In Excel file, the date format is: DD-MM-YYYY (31-12-1999). After upload, it reads: (1970-01-01). It appears it's not seen 31 as Day but Month.

In fact, when I used 11-12-2001  (December 11, 2001), I still got 2001-11-12 (November 12, 2001).

Please, how can I get through this irrespective of the date format in Excel file?






PHP is a widely-used server-side scripting language especially suited for web development, powering tens of millions of sites from Facebook to personal WordPress blogs. PHP is often paired with the MySQL relational database, but includes support for most other mainstream databases. By utilizing different Server APIs, PHP can work on many different web servers as a server-side scripting language.