Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x

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

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
Technology Partners: We Want Your Opinion!
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Dear Experts,
I'm using PHP
I know that some websites use php, but they do not have page extentions like about.php
Do they use folders for every page or do they use something to hide their page extentions?
I click the link, the link is www.domain.com/about-us
do they create about-us folder for every page they have or do they use something for the SEO purposes?
0
Hi,
I have a script that uses a product called PHPDocX, I'm trying to insert an image name from a database based on a $POST value:

?php
$servername = "localhost";
$username = "antony";
$password = "*******";
$dbname = "templatemadness";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
} 
$sql = 'SELECT
id,
letter_logo_image
FROM
template_header
WHERE
[b]id = ******************';//this will need to be a $POST value from index.php[/b]
$result = $conn->query($sql);

if ($result->num_rows > 0) {
    // output data of each row
    while($row = $result->fetch_assoc()) {
        
        echo  $row["letter_logo_image"];//to prove it works!
    }
} else {
    echo "0 results";
}

?>
<?php  echo  $row["letter_logo_image"]; ?>
<?php
require_once 'Classes/Phpdocx/Create/CreateDocx.inc';
require_once 'Classes/Phpdocx/Elements/WordFragment.inc';


$docx = new Phpdocx\Create\CreateDocx();
$docx->modifyPageLayout('A4', array('numberCols' => '1','marginRight' => '400','marginLeft' => '400', 'sectionNumbers' => array(2) ));
//create a Word fragment with an image to be inserted in the header of the document
$imageOptions = array(
	[b]'src' => 'images/***imagename from database***', //this needs to pull the image name from 'letter_logo_image'[/b]
	'dpi' => 600,
);

$headerImage = new Phpdocx\Elements\WordFragment($docx, 'defaultHeader');

Open in new window

0
Dear Experts,
I want to learn why I need to use NULL twice for this nested statement? what is NULL for in this statement?
SELECT table1.uid, 
       table1.isim, 
       NULL, 
       NULL 
FROM   table1 
WHERE  NOT EXISTS (SELECT 1 
                   FROM   table2 
                   WHERE  bayikodu = table1.uid); 

Open in new window

0
<?php
include 'config.php';
$class="";
$message='';
$error=0;
$target_dir = dirname(__FILE__)."/Uploads/";
if(isset($_POST['btn-upload']))
{  
    $target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
	$fileType = pathinfo($target_file,PATHINFO_EXTENSION);
	if($fileType != "csv")  // here we are checking for the file extension. We are not allowing othre then (.csv) extension .
	{
		$message .= "Sorry, only CSV file is allowed.<br>";
		$error=1;
	}
	else
	{
		if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
			$message .="File uplaoded successfully.<br>";
			
			if (($getdata = fopen($target_file, "r")) !== FALSE) {
			   fgetcsv($getdata);   
			   while (($data = fgetcsv($getdata)) !== FALSE) {
					$fieldCount = count($data);
					for ($c=0; $c < $fieldCount; $c++) {
					  $columnData[$c] = $data[$c];
					}
             $name = mysqli_real_escape_string($connect ,$columnData[0]);
             $cpu = mysqli_real_escape_string($connect ,$columnData[1]);
			 $memory = mysqli_real_escape_string($connect ,$columnData[2]);
			 $disk = mysqli_real_escape_string($connect ,$columnData[3]);
			 $nic = mysqli_real_escape_string($connect ,$columnData[4]);
			 $price = mysqli_real_escape_string($connect ,$columnData[5]);
			 
             $import_data[]="('".$name."','".$cpu."','".$memory."','".$disk."','".$nic."','".$price."')";
            // SQL Query to insert data into DataBase

             }
             $import_data = 

Open in new window

0
I am working with a non profit.

I don’t have a good idea of how Access is used yet, it’s my first day.


Would it be recommended to use a web application instead of Access?

The non profit is a mental health clubhouse. Right now people sign in and out on a piece of paper and it’s manually entered into Access.


It seems like if we used a web app we could allow people to sign in and out digitally and access it automatically.


Additionally we could generate CSV files to import into Excel.


Where should I begin in evaluating this decision?
0
Dear Experts,
I select data from my database like this

$sql = "SELECT _key,urun,tarih FROM order WHERE _key between 75 and 120";

$res = $mysqli->query($sql);

if ($res->num_rows > 0) {
    while($row = $res->fetch_assoc()) {
	$key= $row["_key"];	
	$urun= $row["urun"];
	$tarih= $row["tarih"];
	
	if ($key=="98") {$newvariable98=$urun ;}
	if ($key=="106") {$newvariable106=$urun ;}
	if ($key=="120") {$newvariable120=$urun ;}
	
	}
 }

Open in new window


since $row is an array, is there a better way to select key 98,106,120 data? Thank you
0
Dear Experts,
I need to select to some data from my database but this time I think I need to use an array.

I wrote something like this but it is not working?

$sql = "SELECT id,onay FROM urunler where id between 271 and 290";
$info = array();
$result = $mysqli->query($sql);

    while ($row_user = mysql_fetch_assoc($sql)){
    $info[] = $row_user; 	
	}
	
	foreach ($info as $user) {
    echo "Id: {$user[id]}<br />"
       . "Name: {$user[onay]}<br />";
}

Open in new window

Also, I wonder how can I call a specific variable from this array?
For example if I'd like to see what is inside id 271, should I write it like this?
echo $user[onay][271];

Open in new window

0
i am fresher in php: i have table (admin) where two row is there intime,outtime
i wants to calculete time Diffrence and show to frontend how can i do that12.PNG

i Want to show total time diffrence like this format 08.00.12hrs[hours:minutes:second]
0
good afternoon:
i am some issue of display the attence for Each user:
 I Have Two Table :
First Table Contains Admin table Which Conatains:
userid
intime
outtime
second Table Contains use table Which Conatains:
id
username
password
role
I Have a landing page where i am displaying userinformfation from usertable and one link is there viewattendence ,if user click then it display userattendence  based on her id
But issue is there that attenence is in admin table(login and logout):then how can i get the attendence beacause in landing page  user passses id not userid:and url search for id which is not there in admin table
For this issue i am using mysql query is:
$sql = "select admins.id, admins.intime, admins.outtime
                                 from admins inner join userregisters  Having  admins.userid='" . $_GET["id"] . "'";

Open in new window

How can i do that plz suggest me
0
Independent Software Vendors: We Want Your Opinion
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

This should be easy, but it's kicking me squarely in the pants and I don't know what I'm doing wrong.

Here's what I'm using:

      $sql=$conn->prepare("SELECT homepage_id from employers where id=:id");
            $sql->bindParam(':id', $id, PDO::PARAM_INT);
            $row=$sql->fetch();
            $the_name=$row->homepage_id;
            echo $the_name;

I get no errors but no value and there is a value in the database that should be coming up.

What am I doing wrong?
0
This is the last question regarding this webpage. I have records from a database for the last 2 months being displayed on a webpage. It shows the older month on top. I tried to put tables side by side which worked but only 1 header would display for some reason. I am ok with the tables being display 1 on top of the other I would like the most recent month on top. Any time i try and change the display the code has an error and displays nothing. I am not sure if I have to break the data out when displaying. I have attached code and screenshot. I would like Jan on top and then December as there will be a lot of records so will probably have to scroll. Help is always appreciated.
Before.jpg
index.php
0
Hi,
I did check the current .php file but I cannot find out how highlighted message would be trigger, within the Web page.

20u.png
0
Hey

I followed these directions
https://developers.google.com/recaptcha/old/docs/php

And I have the code below. I"m always getting the message that says Google Captcha not working no matter what.


<?php
require_once 'recaptchalib.php';
  require_once '../includes/functions.php';
  redirect_tablet_by($_SERVER['HTTP_USER_AGENT']);
  $title = 'Contact Us';
  $description = 'Contact information and directions for Consolidated Utilities, Coastal Water and Sewage, Coastal Water Company, Whitemarsh Estates
    Water System, Woodlawn Water Savannah Ga, and Golden Isles Water System.';
  $privateKey = 'asdf';
  $errors = array();
  $flag = true;
  $name = null;
  $email = null;
  $address = null;
  $subject = null;
  $message = null;
  $alert = null;

$resp = recaptcha_check_answer ($privateKey,
    $_SERVER["REMOTE_ADDR"],
    $_POST["recaptcha_challenge_field"],
    $_POST["recaptcha_response_field"]);

  if (isset($_POST['submit'])) {
      if (isset($_POST['name'])) {
          $name = stripslashes($_POST['name']);
          $length = strlen($name);
          if ($length < 2 || $length > 40) {
              array_push($errors, 'Name must be between 2 and 40 characters.');
              $flag = false;
          }
      } else {
          $name = null;
          array_push($errors, 'Name is a required field.');
          $flag = false;
      }
      if (isset($_POST['email'])) {
          $email = stripslashes($_POST['email']);
          if (!filter_var($email, 

Open in new window

0
Hi Experts,

Likely this is a Windows issue, but I am posting under PHP just in case.

I'm trying to use PHP to upload files to  the server.  I'm developing, so the server and the client, are actually the same Win 7 x64 PC with IIS.

Once I upload the files using the following script they get locked in the target directory.
        global $PATH_TO_ROOT;
        $attach_dir = $PATH_TO_ROOT . 'attachments/';
        $client_dir = $attach_dir . 'client-' . $client_id;
        
        //Check if client directory exists
        if (!is_dir($client_dir)){ 
            mkdir($client_dir);
            copy($attach_dir . 'client-0/index.php', $client_dir . '/index.php');  //Security-purposes
        }
        
        //Check if Progress Directory exists
        $progress_dir = $client_dir . '/prog-' . $progress_id;
        if (!is_dir($progress_dir)){ 
            mkdir($progress_dir);
            copy($attach_dir . 'client-0/index.php', $progress_dir . '/index.php');  //Security-purposes
        }
        
        //Upload file
        $temp_file = $_FILES['file']['tmp_name'][$file_no];
        $file = str_replace(' ', '_', $file);
        $dest = $progress_dir . '/' . $file;
        move_uploaded_file($temp_file, $dest);

Open in new window


By locked, I mean that I get access denied both when using <a href=".../myfile.txt">and by trying to opening through the File Explorer. The only way to unlock them is by going into Safe Mode as explained here.

I dont think this is my code, but rather my settings in Windows, but I have posted this under both topics. I am also thinking that the IIS_IUSRS is probably doing upload and maybe that is locking it, but it does have full permissions to the root directory.

Any help will be greatly appreciated.
0
Hi,

I am in big trouble. and I hope that somebody can guide me in the right direction.

I have this page http://kroweb.dk/gfdev/godser_raw/godser.php where everything, except the behavior of the Enter key, is working nicely.

You might want to try to enter "Kronborg" into the searchfield an hit the "Søg" (Search) button. A nice result is returned. Try again with the same phrase and hit the Enter key - and the page is reset and results are empty.

I have tried many things, and I have Googled the problem, but nothing seems to work. The strange thing is that I have a similar setup in most of my other pages, and here is it working perfectly.

What am I doing wrong :)

<?php
session_start();
error_reporting(E_ALL);
ini_set('display_errors', 1);
?>

<!DOCTYPE html>
<html lang="da">
<head>
  <!-- Check for title--> 
  <title>Godser</title>

  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">

  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
  <link rel="stylesheet" type="text/css" href="style_godser.css" />
  <link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css">
  <link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/v/dt/dt-1.10.16/datatables.min.css" />

  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
  <script type="text/javascript" 

Open in new window

0
Hi Experts

Could you point what is preventing this code to correctly fire a javascript function when a 2nd input box is added ?

<html>
<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/handlebars.js/4.0.5/handlebars.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/zepto/1.1.6/zepto.min.js"></script>
<script src="../lib/php_crud_api_transform.js"></script>
<script id="PostListTemplate" type="text/mustache">
<ul>
	{{#pessoas}}
		<li>
			<span class="id">{{id}}</span>, <span class="clb_nome">{{clb_nome}}</span> , <span class="email">{{email}}</span> 
			<a href="javascript:void(0)" class="edit">editar</a>
			<a href="javascript:void(0)" class="delete">deletar</a>
		</li>
	{{/pessoas}}
	<li>
		<form>
            <input name="clb_nome"/>

             <!-- Problematic if I add this input box -->
            <input name="email"/>

		</form>
	</li>
</ul>
</script>
<script>
function PostList(element, template) {
	var self = this;
	var url = '../api.php/pessoas';

	self.edit = function() {
		
        // Edition
        
        var li = $(this).parent('li');
		var id = li.find('span.id').text();
		
        var clb_nome = li.find('span.clb_nome').text();
		clb_nome = prompt('Value',clb_nome);

        var email = li.find('span.email').text();
		email = prompt('Value',email);

		if (clb_nome!==null) {
			$.ajax({url:url+'/'+id, type: 'PUT', data: {clb_nome:clb_nome, email:email} , success:self.update});
		}
	};

	self.delete = function() {
		var li 

Open in new window

0
I have a Linux server and I would like a PHP script to monitor a list of websites to check if they are active. For example I would like to check for any websites returning a 500 internal server error. Upon detecting this error I would like an email and SMS notification sent.

I understand the script needs to be called either by a CRON job or internal scheduler on a regular basis such as every 5 minutes.

I wish to reiterate that the websites being monitored are hosted externally on a Windows server but a Linux server will be used to do the monitoring.
0
Hi,

I have this page:
http://kroweb.dk/gfdev/godser/
and my trouble is, that when I try to perform a search nothing happens at all and I get no error messages either.

I have tried to create a query directly in the db editor like this: Sk-rmbillede-2018-01-13-10.47.18.png and it works nicely and returns the expected results.

I am connected to the right db (have doubble checked several times :) ), and I simply can't see why this is not working.

I have this main file:
<?php
session_start();
error_reporting(E_ALL);
ini_set('display_errors', 1);
?>

<!DOCTYPE html>
<html lang="da">
<head>
  <!-- Check for title--> 
  <title>Godser</title>

  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css">
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" integrity="sha512-dTfge/zgoMYpP7QbHy4gWMEGsbsdZeCXz7irItjcC3sPUFtf0kuFbDz/ixG7ArTxmDjLXDmezHubeNikyKGVyQ==" crossorigin="anonymous">
  <link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/v/dt/dt-1.10.16/datatables.min.css" />
  <link rel="stylesheet" type="text/css" href="style_stednavne.css" />

  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
  <script 

Open in new window

0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE
LVL 5
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Hi Experts,

If I have a file at
www.domain.com/downloads/myfile.xlsx

which is at
C:\inetpub\wwwroot\domain.com/downloads/myfile.xlsx

My question is, from  domain.com/mod/index.php, how would I write my <a> tag to engage download?

I have <a href="../downloads/myfile.xlsx" target="_blank">, but I am getting Permission Denied.

Thank you

Edit: This may be a Windows Question.
0
Hello,

I am creating a form which pulls information from my SQL database. Initially my form had two fields, 'language' and 'prefecture' . Thanks to Julian Hansen on this forum, I managed to get the form to work, so that when no values were returned the form processed correctly. My code to do this is below:

  <?php
  
  $language = $_POST['language'];
  $prefecture = $_POST['prefecture'];
  
  $sql = "SELECT * FROM teacher_table WHERE language = '".$language."' AND prefecture = '".$prefecture."' ";
  $result =mysqli_query($db_connection, $sql);
  
  if (count(mysqli_fetch_array($result)) > 0)  
 		{
 
 ...displays output
 
 else{
      // No Results
      redirect_to ('no_results.php');
      db_disconnect($db_connection);
      exit;
      }

Open in new window


However, I am now trying to add a checkbox to the form which has the function of basically   'only show values where photo field entry =1'. So that only entries with photo field = 1 are returned if it is checked and if it is not checked all entries (photo field = 1 or 0) are returned.

 I therefore tried to amend the statement to:
 $sql = "SELECT * FROM teacher_table WHERE language = '".$language."' AND prefecture = '".$prefecture."'  AND   photo = '".$photo."  ";

Open in new window

 
However, the problem with this is (I think?) relates to this line:

if (count(mysqli_fetch_array($result)) > 0)

Open in new window


 If no results are returned from language and prefecture, a result is always returned from photo (either checked or unchecked -1 or 0) so results is always greater than 0? I think that's what's happening from when I run the code. And also, when this box is not checked, it only returns values which are 'not-checked' i.e. 0. It should returns '1 'and '0' values.  

So I'm kind off stuck. I guess I'm looking for a way to use a checkbox in a form where if it is not checked, all values corresponding to that checkbox are returned, and if it is checked, values corresponding to that checkbox which are 'checked' or '1' are returned only.

And I want to do this in a way which doesn't interfere with my  if (count(mysqli_fetch_array($result)) > 0
0
$password=htmlspecialchars($password);
 $sql="SELECT * FROM userregister  WHERE username='$username' and password='$password'";
$result=mysql_query($sql)OR die("Error:".mysql_error());

$row=mysql_num_rows($result);
$userinfo=mysql_fetch_assoc($result);
 $role=$userinfo['role'];
 
 if($row==1){

     $_SESSION['login_user']=$username;
       $_SESSION["userid"] = $id;
  $queryString = "INSERT INTO  admin (userid, intime) VALUES ('{$row[id]}', NOW())";

afterlogin when i isert userid and login time in admin table,,logintime is inserted but userid is showning 0 for all the user:
My Table stucture is
Admin table :
id:
userid:
logintime:
logouttime:
my usertable contain :
id:
username:
password:
role:
0
I have a page that is generated dynamically with a list of Press Releases.  There is another page that pulls the HTML via an AJAX call.  The problem is, is that the HTML page is dynamic.  Is there a way to populate the page before the AJAX call pulls the HTML?
0
I have 4 different companies that have figures/amounts entered every day into access - so multiple rows in access. I want to display the total per company on the webpage.

Company 1: total                             Company 2: total                  Company 3: total                 Company 4: total

I have seen code where SUM is in the query where company equal company 1. Is this the best way to do it? Any help appreciated....
0
Hi all,
I've created a basic search form with 2 inputs from drop down menus which will return results to a results page. My two input fields in the search form are 'language' and 'prefecture'.

My code php below  displays the correct results when there are results in the database. However, when there are no results in the database which match the search criteria,  the code doesn't do what I hoped it would do (i.e. redirect and disconnect). All that happens is that no results are displayed in my results page.  

Any idea what I am doing wrong? Many thanks for reading.

Regards,
Adam

<?php

$language = $_POST['language'];
$prefecture = $_POST['prefecture'];

$sql = "SELECT * FROM teacher_table WHERE language = '".$language."' AND prefecture = '".$prefecture."'";
$result =mysqli_query($db_connection, $sql);

 if($result) { 
    // Results
	While ($rows = mysqli_fetch_array($result)){
	echo $rows['firstname'];
	echo $rows['language'];
	echo $rows['prefecture'];
	}

	
    }
	else {
    // No Results
    redirect_to ('no_results.php');
    db_disconnect($db_connection);
    exit;
    }

?>

Open in new window

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.