PHP

119K

Solutions

32K

Contributors

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

if ($_FILES['bulk']['size'] > 0 ) {
            
                    $file = fopen($filename, "r");
                  if($file)
                  {
                        echo "opend";
                  }
                  else
                  {
                        echo "not";
                  }
            
              while (($get = fgetcsv($file, 10000, ","))!==false)
               {
$class=$get[0];
$first=$get[1];
$last=$get[2];
$gender=$get[3];
$dob=$get[4];
$add=$get[5];
$city=$get[6];
$state=$get[7];
$zip=$get[8];
$mob=$get[9];
$alt=$get[10];
$email=$get[11];
$rfid=$get[12];
 $file = $get[13];
 $file_name = $file[0];
 $file_tmp_name = $file[1];
 move_uploaded_file($file_tmp_name,"../upload/".basename($file_name));
if($i>0)
{
                 $sql = mysql_query("INSERT into student$school (class,firstname,lastname,gender,dob,address,city,state,zip,mobilenum,alternate,email,rfid,image)
                     values ('$class','$first','$last','$gender','$dob','$add','$city','$state','$zip','$mob','$alt','$email','$rfid','$file')") or die(mysql_error());
      
}
$i++;      
               }
                  if(!$sql)
                        {
                        echo "<script>alert('some thing went wrong')</script>";      
                        }
                        else {
                                echo "<script>alert('successfully Imported.')</script>";
                        }
                    
             }
      }
0
Free Tool: Subnet Calculator
LVL 11
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

It seems like when I run the code, the first map function was not able to get the id of restaurant. Is it the reason why my map only shows grey box?
restaurantinfo.php
0
I want to alert a message " Sorry file already existed " when user upload the same files , if the files didn't exist in the database , user can upload the files into database . File name as the detection for duplicated files .

<?php
include 'config.php';


if(isset($_POST['btn-upload']))
{  


$targetDir = "uploads/";
$files = $_FILES['file'];
foreach($files['name'] as $key => $name) {
    $file = $files['tmp_name'][$key];
    $target = $targetDir  . "/" . $name; 
	    

		
		
    if (is_uploaded_file($file)) {
		
		 //open uploaded csv file with read only mode
            $csvFile = fopen($file, 'r');
            
            //skip first line
            fgetcsv($csvFile);
            
            //parse data from csv file line by line
            while(($line = fgetcsv($csvFile)) !== FALSE){
                 //insert member data into database
                    $db->query("INSERT INTO nov(f_name,name, cpu_count, memory_size, disk_space_size, nic_count, power_state) VALUES ('".$name."','".$line[0]."','".$line[1]."','".$line[2]."','".$line[3]."','".$line[4]."','".$line[5]."')");
                }
            
            ?>
  <script>
  alert('successfully uploaded');
        window.location.href='index.php?success';
        </script>
  <?php
  }
 else
 {
  ?>
  <script>
  alert('error while uploading file');
        window.location.href='index.php?fail';
        </script>
  <?php
 }
}		
            //close opened csv file
            fclose($csvFile);
		
		
		
	}

?>

Open in new window

0
Hi Experts,

I am running a PHP MySQL application on Windows 2012 IIS, but it was extremely slow. Changing my db host from localhost:3306 to 127.0.0.1:3306 seem to do the trick. Any idea why?

The hosting company telling me that it is because the DNS lookup, but there is a difference of 7s. Could a DNS lookup take that long?
0
Can anyone recommend an "easy way" to include address validation into my Wordpress forms and woocomerce order page? I know that UPS has a PHP API that I am eligible to use since I have an account with them but I'm uncomfortable doing any PHP coding so was looking for some help or direction on the best way to proceed. I also have accounts with USPS and FedEx if those have solutions I don't know about--thank you.
0
I'm changing delivery options on my WooCommerce checkout page via functions.php file and I need to refresh the page if radio button is checked. I can't get it to work, since I don't understand how to do it?

So at the moment that's the code:

    add_filter('woocommerce_checkout_fields', 'xa_remove_billing_checkout_fields');
    function xa_remove_billing_checkout_fields($fields)
    {
       $shipping_method ='flat_rate:3'; // Set the desired shipping method to hide the checkout field(s).
       global $woocommerce;
       $chosen_methods = WC()->session->get( 'chosen_shipping_methods' );
       $chosen_shipping = $chosen_methods[0];
      
       if ($chosen_shipping == $shipping_method)
       {
          unset($fields['billing']['billing_address_1']); // Add/change filed name to be hide
          unset($fields['billing']['billing_address_2']);
       }
      
       return $fields;
    }

Can I add some code somewhere to make it refresh? I've tried different methods, but nothing..

Thank you in advance!
0
I recently purchased an Onion Omega2+ micro processor, and succeeded at getting it hooked up to their "Onion Cloud", .. where I can supposedly tap the device's API and remotely control it over the internet using CURL commands similar to the following (note that I've excluded my actual API key for obvious reasons):

curl -H "Content-Type: application/json" -H "X-API-KEY: <Your_Api_Key>" -X POST -d '{"command":"aplay","params":["/tmp/mounts/SD-P1/noodle.wav"],"env":""}' https://api.onion.io/v1/devices/c7477c88-f547-4b4e-9782-507e0c2bd386/file/exec

Open in new window


Does anyone here have any idea how I might translate this into PHP code that would run under PHP 7 ?  

Thanks,
- Yvan

P.S. Note that I do NOT have access to the command line on my shared hosting environment were I'd like to test the PHP script.
0
Hi,
how I can parse a String with XML content to nodes so I can get quick accesss to the values?

<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tns="http://xxx:8082/api?ws=1"><soap:Body><tns:alterMultipleCorpusParameter><alterMultipleCorpusParameterById><corpus>REC::MR171127da1e507b8ad0b12534c0ec18067526325a1d6ecf02e66</corpus><parameterValues><items><key>Korpus_Hoehe</key><value>1000</value><type>Grundeinstellungen</type></items><items><key>Korpus_Breite</key><value>700</value><type>Grundeinstellungen</type></items><items><key>Korpus_Tiefe</key><value>600</value><type>Grundeinstellungen</type></items></parameterValues></alterMultipleCorpusParameterById></tns:alterMultipleCorpusParameter></soap:Body></soap:Envelope>

Open in new window

I want to get the all key and their values in the output, like Korpus_Tiefe = 600 and so forth.
0
I have 8 columns in my table. The first 4 display data from the table. The last 4 columns display the data of the next for dates as column headers. This part works. What i want under each of the 4 data is the status of the work. So if it is between this data and the next date todays status is xxxxx, if tomorrows data is between is and that then tomorrows status is xxx and so on for 4 days.

I am just having issues with figuring out the logic logic....I have added the switch statement but it is more the logic that the correct way of putting it...

I have attached the file...
index.php
0
Hi EE.

This may sound confusing but I have a textbox which is a cell number textbox and I want when the max length of 10 has been reached then fire the php code which is inside the same html page as form and this php code will then get the value or data which has been keyed in to this text box. I've tried Javascript and the problem I'm having with javasacript is to now display this data so that why I've deiced to change to php because I know how to display the php session data within the textbox with something like
<input  type="text" id="dCell" value="<?php echo $_SESSION['mySessionIDHere'];?>">"

Open in new window

so I tried to do something like this but with javascript but the whole tag codes just show on screen when I run load the page so that why I've choose to go with php.

Please do note that the page is HTML and the input from which I want to take the data from is also in html not php the php function script will be written within the html page so all of this will be in one page not that it will be passed to another page no.
0
Get expert help—faster!
LVL 11
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

I'm using Wordpress and I have created a posts array using get_posts (a list of attachments IDs of type image).
This populates the array with the post IDs that I'm interested in. I would now like to add an associated item to each of the array entries so that I end up with something like this.
1234  ABCD
2343 FDRE
4324 HGRD

The first column is the postID and the second column is the associated string that I've added (from a lookup).
The reason for this is I would like to sort the array into ascending order on the second column which will then put my post IDs in the same order. When I display the images using the post ID, they will be displayed in the order defined by column 2.
0
Hi Experts

Could you explain what is the purpose of "Docker" use and recommend some good references on it?

Is it in some manner near "git" ?

From a day to another I had to start using this software.

There's a "pletora" of materials on internet but some of them could be more adequated.

Thanks in advance.
0
Dear sir
i am getting Error when i upload  my php code on live website,but in localhost in myssytem,it's working fine,but in live i am getting error::This is my code for login

my dbconfig.php
<?php
         $dbhost = 'localhost';
         $dbuser = '*****';
         $dbpass = '*****';
         $dbname = '*****';
         $conn = mysqli_connect($dbhost, $dbuser, $dbpass,$dbname);
   
         if(! $conn ) {
            die('Could not connect: ' . mysqli_error());
         }
       
        ?>

Open in new window

And  Authenticate.php
<?php ini_set('display_errors', '1'); ?>  
<?php
require_once("dbconfig.php");


 $username=$_POST['username'];
 $password=$_POST['password'];

 $username=stripcslashes($username);
 $username=mysqli_real_escape_string($conn,$username);
 $username=htmlspecialchars($username);
  
 $password=stripcslashes($password);
 $password=mysqli_real_escape_string($conn,$password);
 $password=htmlspecialchars($password);
$sql="SELECT * FROM userregisters  WHERE username='$username' and password='$password'";
$result=mysqli_query($sql);

$row=mysqli_num_rows($result);
$userinfo=mysqli_fetch_assoc($result);
 $role=$userinfo['role'];
 
 if($row==1){

           $_SESSION['login_user']=$username;
	       $id =$userinfo['id'];
		   $_SESSION["id"]=$id;
          $_SESSION["userid"] = $id;
		  
  $queryString = "INSERT INTO  admins (userid, intime) VALUES ('{$userinfo['id']}', NOW())";
  $result=mysqli_query($conn,$queryString);
 $row1=mysqli_num_rows($conn,$result1);
  if($role=='admin'){
    
    
  header('location:admin.php');
  }
  if($role=='user'){
    
  header('location:user.php');
  }   
   
 }else{
  echo "No User Found by Given Information";
 }
  
 
?>

Open in new window

Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, null given in /home/salenbuy/public_html/manoj/login/authenticate.php on line 32

Warning: Cannot modify header information - headers already sent by (output started at /home/salenbuy/public_html/manoj/login/authenticate.php:2) in /home/salenbuy/public_html/manoj/login/authenticate.php on line 40
0
Hello,
Is it possible to encode a JSON in PHP in Java-Script Style?
As sample,

[
	{ id:6, status:"new", text:"Task 6", tags:"webix,kanban", comments:[{text:"Comment 1"}, {text:"Comment 2"}], personId: 2 },
];

Open in new window


A similar export I did is:

[
	{ "id":"6", "status":"new", "text":"Task 6", "tags":"webix,kanban", "comments":"[{"text":"Comment 1"}, {"text":"Comment 2"}]", "personId": "2" },
];

Open in new window


Special the part:
comments:[{text:"Comment 1"}, {text:"Comment 2"}]

Open in new window

looks like a JSON encoded string inside a JSON?
How is this possible to generate with an SQL query?
0
I have the entire table printing out with column names and data. It displays 8 columns but i just want it to display the first 4 columns names/headers only and want the last 4 headers to show the next 4 dates from today (today, tomorrow....) .

For the data I just want o show the first 4 columns of data and logic/formula for the last 4.

Can you help me to print out only 4 header from array and static for the last 4 headers?

I have uploaded the code.
index.php
0
Hi Experts,

I have the attached table structure showing only related fields to this questions. For those columns without a heading, I just inserted the client name to reference in this question

I need to show the number of clients served by a given user by service.

For example, user Nataliia had 3 clients (Alissia, Peter and Rose). Under the progress_details you will see that Rose needs help with Family Matters and Senior Support.

Therefore, Nataliia is serving clients that need

1. Senior Support
1. Family Matters

This is part 1.

Part 2 is that If possible, I also need to account for intake.services. So, also under Nataliia:

Alissia needs 12 (Debt Management) and 10 (Employment)

Peter needs Housing

and Rose needs Family Matters and Senior Support.

So, from part 1 plus part 2, Nataliia's final report should be.

1. Senior Support *
1. Family Matters *
1. Debt Management
1. Employment
1. Housing

*Since Senior Support and Family Matters are for Rose, both in Intake and in Progress Details they are for the same client and therefore counted once, but if Peter also require Family Matters then for Nataliia Family Matters would have been 2.

If part 2 is too complex, then I could run a separate query and calculate it with php. But, I don't know how to approach part 1 as well. I would definitely need distinct client_id.
Table-Structure.xlsx
0
Hi Experts

Could you point the better tools to develop PHP/ MySQL on Ubuntu?
Possibly free.
I'm using PHPDesigner/ dbForge on Winodows environment and had to change.

Thanks in advance
0
Hi,
I'm using a form building script, using Ajax Autocomplete, the include file looks like this
<?php
$array = ['Mildred', 'Louise', 'Frances'];


Search 20 results
$max_results = 20;
$found = 0;
$results = [];
for ($i=0; $i < count($array); $i++) {
    if (preg_match('`' . addslashes($_GET['term']) . '`i', $array[$i])) {
        array_push($results, $array[$i]);
        $found += 1;
        if ($found == $max_results) {
            $i = count($array); // end loop if we reached max_results
        }
    }
}

if (count($results) > 0) {
    $out = '[';
    for ($i=0; $i < $found; $i++) { // returns only firs 20 results
        $out .= '"' . $results[$i] . '"';
        if ($i + 1 < $found) {
            $out .= ',';
        }
    }
    $out .= ']';
    echo $out;
}

Open in new window


Problem is I want the array data from a MySQL query, I have tried using an include to an external page that returns the results but fails:

<?php
//Step1
 $db = mysqli_connect('******','****','*****','*********s')
 or die('Error connecting to MySQL server.');
?>


<?php

$query = "SELECT * FROM templates_client_search";
mysqli_query($db, $query) or die('Error querying database.');

$result = mysqli_query($db, $query);
$row = mysqli_fetch_array($result);

while ($row = mysqli_fetch_array($result)) {
 echo "'" . $row['ContName'] . " - " . $row['ContAddress'] . "', ";
}
?>

Open in new window



Any ideas or pointers please?
0
I want to force someone to change their password after 60 days. I'm going to write how I was planning on doing it and see if you experts have any recommendations for me.

So I'm going to use Date or Date time - that doesn't matter how I generate 60 days.

I want to render the user incapable of performing any tasks until they change their password.

Here's how I was going to do it
-Do not set a cookie
-load a change password page with a hidden input that had their username
-set some form of access control

Is this stupid? Should I use a cookie?

Thanks
0
Hire Technology Freelancers with Gigs
LVL 11
Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Hi

I run web applications with PHP, SQLSRV and MS SQL (2014 web).

With the forthcoming GDRP legislation I am considering encrypting my sql databases. Please can anyone advise if ugrading to SQL Server 2016 (web) and using AlwaysOn Encryption is a possibility. I would like to not have to recode all my queries, but could easily change my connection strings.

I am also looking at row-level security as my database tables are shared across multiple clients, with an an identifiying "clientid" on each record to distiguish which record belongs to which client. Can anyone advise if this is possible and practical.

Thank you
0
Hi

I know this is a question is already mentioned but i wanted to know with the code below, can i upload the row on that day. Ie 9/12/17 it displays the info from that row (not the date).

PHP Code
<? 
$fulltext = file_get_contents("data/test1.txt"); 
$linearray = explode("\n", $fulltext); 
foreach($linearray as $line => $text){ 
    $fullarray[] = explode("\t", $text); 
} 
echo "<table>"; 
foreach($fullarray as $key => $value){ 
    echo "<tr>"; 
    foreach($value as $which => $text){ 
        echo "<td>{$text}</td>"; 
    } 
    echo "</tr>"; 
} 
echo "</table>"; 
?>

Open in new window


Text File
			Morning		Afternoon		Evening
8/12/17			10am		12pm		6am
9/12/17			9am		1pm		7am
10/12/17			8am		2pm		6am

Open in new window


A test output is here: click here. However the real output i would like is attached, in a html table format.
test1.xlsx
0
I installed Laravel.

I created a virtual host on my computer with the hostname laravel.local.

When I installed Laravel I chose the name sample-application, and when it installed it, it  created a directory in my public directory that was called sample-application.

My question is really dumb, but because of apache mod rewrite, you won't have to move files around to display a page for laravel.local right?



Screenshot-from-2018-01-20-10-39-25.pngScreenshot-from-2018-01-20-10-39-28.pngScreenshot-from-2018-01-20-10-39-21.png
0
Hi,

Currently am working php & Php frame work projects .

Please tell me Good topic for seminar related to recent It technology .  Help me to select topic.Please give me some suggestion to  select topic.
0
Hi Experts,

I just created a little application in PHP and MySQL, and on my localhost it is very quick, but when I upload it to my VPS at http://crm-cor.aces-project.com/ it is very slow, even the login page.

There is not that much activity on this server, and I have other applications on there that are fast, but can anyone tell what it could be? Both my localhost and VPS are IIS.

This is a test copy, so the credentials are :

aleks@aces-project.com
testing


As well, I am using Google API, which I installed on my localhost with Composer, but on the VPS. I just uploaded it for now. Could that be it?
Any help will be greatly appreciated.
0
I would like to use cookies to remember a login.

I know how to use sessions but not cookies.

Do you use both at the same time?

If you want to post a brief example I would really dig that.
0

PHP

119K

Solutions

32K

Contributors

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.