PHP

118K

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

Hi Experts,

I am building my second WP site, and I am wondering why the Header Image (under Appearance >Header) is appearing in the middle?

I thought the middle is for the Featured Image?

How can I make the header image appear in the top left corner above the site name?  As well, how can I lower the site navigation to be just above the blue line?

If I need to adjust the code, not an issue, but how can I create the child theme and where do I adjust?

I am pretty knowledgeable in PHP, HTML, CSS, etc, I just need a reminder what's where in WP. I am using the Flex-Lite theme.
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!

I have the need to have a php page be embedded into the framework of Prestashop.  I have followed a discussion on how to add a php page but I am still not getting it to work and there is a fatal error.

Here is my php code in /override/controllers/front called Assessment.php

<?php

class AssessmentControllerCore extends FrontController {

/**
 *  Initialize controller
 *  @see FrontController::init()
 */
public function init() {
    parent::init();
}

/**
 *  Assign template vars related to page content
 *  @see FrontController::initContent()
 */
public function initContent() {
    parent::initContent();

    $this->setTemplate(_PS_THEME_DIR_.'assessment.tpl');
}

}
?>

Open in new window


Here is my .tpl file which is located in /themes/warehouse called assessment.tpl
{php}
<?php
echo "sdf";
?>
{/php}

Open in new window


I am calling it in this manner http://www.abc.com/index.php?controller=Assessment and I am getting this error

[Thu Aug 17 18:03:21.105090 2017] [:error] [pid 12287] [client 69.34.35.119:57139] PHP Fatal error:  Class 'Assessment' not found in /data/web/abc.com/classes/controller/Controller.php on line 128

Open in new window


Please help me get my simple php to work so that I then can add in my actual script.

Thanks,
0
I'm facing this problem where the scraper gets stuck and when I refresh the page it resets the scraping from the beginning. Is their a way to make the scraper go straight to where it left off from then start at the begging. The scraper is php build and it uses simplehtmldom to get the content.

Note: I have limited knowledge in scraping in general.

function get_web_page( $url )
{
    $user_agent='Mozilla/5.0 (Windows NT 6.1; rv:8.0) Gecko/20100101 Firefox/8.0';

$options = array(

    CURLOPT_CUSTOMREQUEST  =>"GET",        //set request type post or get
    CURLOPT_POST           =>false,        //set to GET
    CURLOPT_USERAGENT      => $user_agent, //set user agent
    CURLOPT_COOKIEFILE     =>"cookie.txt", //set cookie file
    CURLOPT_COOKIEJAR      =>"cookie.txt", //set cookie jar
    CURLOPT_RETURNTRANSFER => true,     // return web page
    CURLOPT_HEADER         => false,    // don't return headers
    CURLOPT_FOLLOWLOCATION => true,     // follow redirects
    CURLOPT_ENCODING       => "",       // handle all encodings
    CURLOPT_AUTOREFERER    => true,     // set referer on redirect
    CURLOPT_CONNECTTIMEOUT => 120,      // timeout on connect
    CURLOPT_TIMEOUT        => 120,      // timeout on response
    CURLOPT_MAXREDIRS      => 10,       // stop after 10 redirects
);

$ch      = curl_init( $url );
curl_setopt_array( $ch, $options );
$content = curl_exec( $ch );
$err     = curl_errno( $ch );
$errmsg  = curl_error( $ch );
$header  = curl_getinfo( 

Open in new window

0
This is my main.html codeThis is my main.html codeThis is my insert.php codeAnd this is the error which always arises whenver i use localhostHi There I have been getting this issue lately. I don't know where this error come from. Whenever I use my localhost(Obviously i need it for my php files to run) this error arises in console

Error in response to storage.get: SyntaxError: Unexpected token <
    at Object.callback (chrome-extension://nkeimhogjdpnpccoofpliimaahmaaome/js/content.js:1:50)
    at chrome-extension://nkeimhogjdpnpccoofpliimaahmaaome/js/content.js:1:22

This error occurs for all files which i open using localhost.But when I used without localhost ie simply open the html file it works just fine.
Currently I'm learning Angular.js
Here I want to insert data in database using ANGULAR & PHP
0
CppComet
CppComet is open source comet server. In this article i tell about CppComet features and will show an example of a chat on PHP and CppComet.
0
I've been tasked with fixing a bug on the app that we have. When you attempt to cancel an appointment, you get an error.

Using Google Dev Tools, I get this when click on the button:

screenshot
I'm trying to figure out what PHP function is being triggered by this button so I can then troubleshoot that functionality directly. I'm thinking I would look for a file called jquery.min.js, but I can't find it.

Then again, maybe this is just referring to some JQuery functionality.

This is all coming from a Symfony dynamic.

How can sniff out the query that's being used?

Ideas?
0
I am refactoring an older system written in Php/Mysql.  In this code I am seeing several instances of 'return -1' and I'm not clear why this could be.

function mysql_connection($database){
      if(!isset($database)){
            return -1;
        }

        more code ...
}

I'm a novice and have not found an answer in any of my research.

Can someone help me understand why this would be used?
0
Thank you for looking at my question,

I think it's fair to say I'm not really sure what I'm doing, but having read some stuff on here and from other sources I've cobbled this together - it doesn't work, can anybody help me put it right.

I have a php form with three input boxes main, rtd and combined (mimics production paperwork). I want, as the user tabs away from main or rtd, to sum the values of main and rtd and display the result in combined - I'm sure this is possible  I just don't know how to achieve it.


								echo '<table>';
									echo '<tr>';
										echo '<td colspan="4">Strain Gauge Before Stretching</td>';
										echo '<td>MT Strain Gauge</td>';
										echo '<td align="center">Main</br><input type="text" id="main" OnChange="jsCalculate()"/>&Omega</td>';
									echo '</tr>';
									echo '<tr>';
										echo '<td>MT Strain Gauge RTD</td>';
										echo '<td align="center"><input type="text" id="rtd" OnChange="jsCalculate()"/>&Omega</td>';
										echo '<td align="center">Combined</br><input type="text" id="combined"/>&Omega</td>';
									echo '</tr>';
								echo '</table>';
							echo '</td>';
							echo '<td width="50%" align="center">';
							echo '</td>';
						echo '</tr>';
					echo '</table>';
				echo '</td>';
			echo '</tr>';
		echo ' </table>';
	}
?>
<script language="javascript">
	function jsCalculate(){
		var SGMain = document.getElementbyid("prestretchmain").value;
		var SGRTD = 

Open in new window

0
I have inherited a program where the date field in a MySQL table is really a VARCHAR field.  The date looks like this string:  1260777185.  I can't change the format of the field because of various reasons.  How can I change/convert this field to a date format in my query?  It needs to be done at the query level.  The field is called timestamp.  

I'm using this query, but the field is blank once the query has been run.

SELECT amount, description, STR_TO_DATE('timestamp', '%m/%d/%Y') AS transdate FROM transactions

Thank you.
0
I have a database query that I want to export or convert to a json file.

The query result is something like this

path                         | name          
parameter.name.menu.myname | mike miller

Open in new window


Finaly I need a json structure like

"parameter": {
        "name": {
              "menu": {
                    "myname": " mike miller"
              }
         }
 }

Open in new window


How this is possible?
I work with mysql 10.1.x and php
0
Free Tool: Port Scanner
LVL 9
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Hi Experts

Could you point what is the default algorithm to create passwords in CakePHP 3 ?

I need to create a mock user to start testing an  CakePHP 3 app - so a line must be included in the Users table
with a login and correspondent password.

Thanks in advance!
0
I'm using this little function in order to "see" the results of a prepared SELECT statement:

<?php

function interpolateQuery($query, $params) {
    $keys = array();

    # build a regular expression for each parameter
    foreach ($params as $key => $value) {
        if (is_string($key)) {
            $keys[] = '/:'.$key.'/';
        } else {
            $keys[] = '/[?]/';
        }
    }

    $query = preg_replace($keys, $params, $query, 1, $count);

    #trigger_error('replaced '.$count.' keys');

    return $query;
}

function select() {

$query="SELECT usrID ,E.empID ,usrEEID ,usrFN ,usrLN ,usrDOB ,usrCity ,usrState ,usrZip ,usrUsername ,usrPassword FROM hraUsers U INNER JOIN Employers E on U.empID = E.empID INNER JOIN ChannelPartners CP on E.cpID = CP.cpID WHERE usrDOB = ? AND usrEEID LIKE ? AND E.empPID = ?";

$params=array();
$params=array("08/26/1963", "12345", "8975");

$test=interpolateQuery($query, $params);
echo $test;

}

$view=select();

?>

Open in new window


You can see it in action at http://brucegust.com/adm/applied/pdo_sql_test.php

The page that I'm trying to troubleshoot is a little more complicated.

Here's the SQL:

SELECT usrID ,E.empID ,usrEEID ,usrFN ,usrLN ,usrDOB ,usrCity ,usrState ,usrZip ,usrUsername ,usrPassword FROM hraUsers U INNER JOIN Employers E on U.empID = E.empID INNER JOIN ChannelPartners CP on E.cpID = CP.cpID WHERE usrDOB = ? AND usrEEID LIKE ? AND E.empPID = ?

The $params, when I do a var_dump, look like this:

array(3) { ["usrDOB"]=> string(10) "11/28/1990" ["usrEEID"]=> string(7) "12345sp" ["E.empPID"]=> int(7542) }

Consequently, when I run everything through the interpolateQuery, I don't get the values, I get the keys.

When I do a var_dump on the first example, I get three string values:

array(3) { [0]=> string(10) "08/26/1963" [1]=> string(5) "12345" [2]=> string(4) "8975" }

So, I'm thinking I need to run my $params through some kind of loop to eliminate the keys so I'm left with just the values.

How would I do that?
0
Hi, just wondering if it's possible and someone can show me how to remove predefined tags (inc content) based off class name from a string.

E.g.
$string = '<div>
  <div class="abc">abc</div>
  <div>testing</div>
  <div class="def">def</div>
</div>';

// class names
$toRemove = array("abc", "def");

function removal($string) {
  // some how loop through and remove all tags including content based off class name
}

echo removal($string);

Open in new window


Output would be:
<div>
  <div>testing</div>
</div>

Open in new window


Many thanks!!
0
i am finding it difficult to get radio button value in php using jquery ajax. every thing work fine if i comment the radio button variable in the php file  below, but if i remove the comment , nothing works. i have been on this for more then a day now. thanks for the help!!!

here is the html and jquery file :
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width">
    <title>Form Validation</title>
	<style>
		.error{
			color:red;
		}
		
		.emai{
			border: solid 2px green;
		}
		
		.error2{
			color: green;
		}
		.textBoxError{
			border: solid 2px red;
	       color: red;
		
		}
	</style>
</head>
<body>



<form method="POST" id="form" name="form" action="">
    <label for="email" >Enter your email</label>
    <input id="email" class="emai" name="email">
	<p id="result"></p>
	<label for="email">Enter your first name</label>
	<input id="firstname" name="firstname">
	<label for="address">address</label>
	<input id="address" name="address">
	 Yes: <input type="radio" name="opt" value="yes">
    No: <input type="radio"  name="opt" value="No" checked="checked">
	<p id="result2"></p>
    <button id="submitform">Submit</button>
	<p id="result3"></p>
</form>

<script src="https://code.jquery.com/jquery-3.1.0.js"></script>
<script>
$( document ).ready(function() {
    $(function(){
        $('#submitform').on('click',function(e){
            e.preventDefault();  // do not allow the default form action
            var 

Open in new window

0
I am using the below RewriteRule which does what I require. However it effects any other created folders within the "materials/guide/" folder. Can I change it so it only applies to the "materials/guide/details/ folder?

RewriteRule ^materials/guide/([A-Za-z0-9-]+)/?$ /materials/guide/details/index.php?link=$1 [NC]

Open in new window


Or exclude other sub folders in "materials/guide/" if easier?
0
Hello Experts,

I created a 19 question PHP survey program using HTML text areas. It is hosted on my employer's network and can only be accessed via a work computer. The results are anonymous, to some extent. Although I do not collect the survey taker's information, I work in a small department and my boss would know that it came from someone currently working at the moment. My department is open 24/7, 365. So, instead, my boss wants me to dynamically generate a PDF, upon the user's submission, which is not a huge ordeal...but...

How would I accommodate various users' responses, i.e., shorter responses versus longer responses? It'd be nice if each pdf was restricted to X pages, but I don't want to restrict the end user's answer.

Also, if the data extends beyond one page, how do I create additional pages? Would I just use another instance of $pdf->AddPage();?
0
I'm pulling data from a table using PHP.  The data goes into a form with inputs.  The data in the form is good on the page, but when I click the 'submit' button, the only data that's posted is the last record.

I uploaded a test page here...

http://testregister.cenational.org/admin/commitment/test.php

that goes to a page that echos the POST.  It must be something simple I'm missing, so any ideas are appreciated.

Here's the code of test.php

<?php 
	$id_commitment='testCommit';
	$id_event='mo14420';

	//Store registrants into array_registrations
    try {
		$qry_registrants = new PDO("mysql:host=$xxxxx=$xxxxx",$xxxxx,$xxxxx);
	
		$sth = $qry_registrants->prepare("SELECT 
				table1.fm_lname,
				table1.fm_fname,
				table1.id_family_member,
				table2.f_city,
				table2.f_state
			FROM
				table1, table2, table3
			WHERE 
				table2.id_family=table1.id_family AND
				table3.id_family_member=table1.id_family_member AND
				table3.id_event='$id_event' 

				");

			$sth->execute();

			$qry_registrations = null;
				} 
				catch (PDOException $e) {
				print "Error!  Please email steve@cenational.org";
				die();
			}

			/* Fetch all of the remaining rows in the result set */

			$array_registrations = $sth->fetchAll(PDO::FETCH_ASSOC);
?>
<form action="test_code.php" method="post" enctype="application/x-www-form-urlencoded" id="form1">
    <table border="1" align="center">
        <tr>
            <td colspan="3" align="center"><h2>&nbsp;</h2></td>
        

Open in new window

0
Hello, Experts,

I built a PHP script that queries a database and outputs the results in JS/HTML form. If you could review the code below, I need help how to make the result field URL clickable.

Example:

Name: John Doe
URL: http://google.com

When results display for John, he is able to see the result set for his name and click on http://google.com

Let me know if you need further clarification.

<?php
//fetch.php
$connect = stuff
$output = '';
if(isset($_POST["query"]))
{
 $search = mysqli_real_escape_string($connect, $_POST["query"]);
 $query = "
  SELECT * FROM emp_details 
  WHERE dept LIKE '%".$search."%'
  OR fname LIKE '%".$search."%' 
  OR lname LIKE '%".$search."%' 
  OR pkid LIKE '%".$search."%' 
  OR url LIKE '%".$search."%'
 ";
}
else
{
 $query = "
  SELECT * FROM emp_details;
 ";
}
$result = mysqli_query($connect, $query);
if(mysqli_num_rows($result) > 0)
{
 $output .= '
  <div class="table-responsive">
   <table class="table table bordered">
    <tr>
     <th>pkid</th>
     <th>fname</th>
     <th>lname</th>
     <th>department Code</th>
     <th>url</th>
    </tr>
 ';
 while($row = mysqli_fetch_array($result))
 {
  $output .= '
   <tr>
    <td>'.$row["pkid"].'</td>
    <td>'.$row["fname"].'</td>
    <td>'.$row["lname"].'</td>
    <td>'.$row["DEPT"].'</td>
    <td>'.$row["url"].'</td>
   </tr>
  ';
 }
 echo $output;
}
else
{
 echo 'Data Not Found';
}

?>

Open in new window

0
I need to create a language agnostic hashing algorithm for a custom PHP-based application that I'm developing.  

The reason it needs to be language agnostic is because the PHP application that I'm developing needs to be able to communicate with another 3rd party application (hosted on Heroku) .. and both applications need to be able to apply the same exact algorithm.

I understand that its considered bad practice to use a hardcoded SALT value when applying hashing algorithms, but in this particular scenario, I suspect that it may be unavoidable.  I'm all ears, however.  Still .. let me explain what it is that I need to do first.

Here's what I currently have set up in my PHP application:

$param1= 'beta';
$param2= 'noodle';
$param3= '1502719494';
$hashstring = $param1. $param2. '-' . $param3;  
$options = [
  'cost' => 10,
  'salt' => 'Dk2jdfPIJFddf32948jdfg809fiejf',
];      
echo password_hash($hashstring, PASSWORD_BCRYPT, $options);

Open in new window


What I'd like to do is to somehow re-write this in a way where it could be interpreted universally in pretty much any programming language, .. but where they can both use the same hardcoded SALT value, and both return the exact same result.  The Heroku application is apparently a Node.js powered application (written in Google V8 JavaScript) .. if that information helps any.  

Anyways, .. I'd be interested to hear anyone's thoughts regarding what I'm trying to accomplish here.

Thanks,
- Yvan
0
Free Tool: Site Down Detector
LVL 9
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

I googled but i was only able to get top n rows or random rows is that possible to fetch it % of rows for every customers .
0
Thank you for looking at my question,

I have a user input form (php) that has some javascript validation which should, if the conditions are met, assign a value to a hidden form element but it isn't working and I can't see why.
	<form name="Form1" action="Forms/Section1.php" method="GET" onSubmit="return jsValidate()">
		<input type="hidden" name="StockItem" />

Open in new window


The javascript validation looks like this
if (z.length == 23){
	if (z.slice(0,2) == "VE" || z.slice(0,2) == "SE"){
		
		//alert("So Far So Good");
		
		document.getElementById("StockItem").value = 1; //Full Build
		alert (document.getElementById("StockItem").value);
	} else {
		errorcount++;
		document.getElementById('VECO').style.color='#FF0000';
	}
} else if (checknum==1){
	
	//alert("So Far So Good");
	
	document.getElementById("StockItem").value = 0; //Component
	alert ("Assembly Stock Item: " + document.getElementById("StockItem").value);
} else {
	errorcount++;
	document.getElementById('VECO').style.color='#FF0000';
}

Open in new window


If either of the conditions are met (z == 23 characters starting VE or SE, or checknum == 1)  then, when it's not commented out, the "So Far So Good" alert appears on the screen but the following
alert(document.getElementById("StockItem").value);

Open in new window

doesn't
and no value is assigned to the StockItem element - as can be seen in the address of the php page the data should pass to
http://xx.xx.xx.xx/ed1/Forms/Section1.php?StockItem=&Meter=1000&ProdnOrder=553456789&SalesOrder=9999&SerialNo=&VECode=VE884S05E0G0T01D0004000

Open in new window


What am I missing?
0
Somebody did a website for a friend of mine. all fine, but when i fill the information and fill the information in "contact us" page, I get lots of error. The friend asked my help to sort this out. you can try this for yourself from this web page http://www.netsys.com.mm/contact
0
I had this question after viewing Need If Logic Help That Assigns Different Unique Values.

On the earlier question
// simulate your post
$post = array('illness','fruits');

Open in new window

 these questions are selected manually but I need them to be dynamic based on the users form input.

I have read that if a checkbox isn't selected no values are transmitted but it seems I have something miscoded in my code.  

I thought this line for the immune column
// simulate your post
$post = array('illness','difficulty','odor','antibiotics');

Open in new window

would only produce the value of 3 if I checked the illness question.  Instead it gives a value of 7.  3 for illness + 3 for antibiotics and 1 for difficulty.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
 "http://www.w3.org/TR/html4/loose.dtd">

<html>
<head>
<title>Count Checks</title>
</head>
<body>
<h1>Count Checks</h1>
<form method="post">
General Health & Vitality<br />
Please check all that apply<br />
Illness More Than Twice A Year:<input type="checkbox" name="illness[]" value=""><br />
Monthly Female Concerns:<input type="checkbox" name="female[]" value=0><br />
Difficulty Digesting Certain Foods:<input type="checkbox" name="difficulty[]" value=""><br />
Body Odor and/or Bad Breath:<input type="checkbox" name="odor[]" value=""><br />
Recent Or Frequent Use Of 

Open in new window

0
I'm trying to be 100% sure that I get responses from AJAX regarding the current state of the process.

I wrote the following as a simulation and its waiting and showing both success and complete at the same time.

$(function() {

	$('#submit').click(function(e){
		e.preventDefault();

		$.ajax({
			
			type: "POST",
			url: "ajaxPost.php",
			data: $("#aiForm").serialize(), // serializes the form's elements.

			success: function(){
				console.log('imStartingNow');
			},

			error: function(jqXHR, textStatus, errorThrown) {
				alert(errorThrown);
			},

			complete: function(){
				alert('im all done!');
			}

		});

	});

});

Open in new window


This all looks fine on the surface.  I am receiving the post variables as expected, however in real life, this post request does some processing that takes awhile so I want to know when it starts and when its done so I made my php script look like this to simulate a wait

<?php 
         sleep(5);
          echo "OK DONE";
?> 

Open in new window


What happens is that NOTHING occurs for the 5 second wait and then both success and complete fire off at the same time.

I was thinking it might be the sleep simulation that is causing the issue, but on my real page where its an actual post with some long processing afterward, it too will hang until done and show both success and complete.  I need some education on the proper way to set up this request where I can separate and identify the success vs the complete.
0
This is my first foray into JSON and I'm trying to develop an autocomplete field with JSON, php and sql.  I've got it working on a single field (employee Name) but would like to add a second field that gets populated by the employee title when the employee name is selected.  

So far, my test page looks like:
<!DOCTYPE html>
<html>
<head>
    <title>Autocomplete Textbox Demo | PHP | jQuery</title>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>
    <link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/themes/smoothness/jquery-ui.css">
    <script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script>

    <script type="text/javascript">
        $(function() {
            var availableTags = <?php include('fetchEmpName.php'); ?>;
            $("#empName").autocomplete({
                source: availableTags,
                autoFocus:true
            });
        });
    </script>
</head>
<body>
<label>Department Name</label></br>
<input id="empName" type="text" size="50" />
<input id="empTitle" type="text" size="50" />
</body>
</html>

Open in new window


And the fetchEmpName.php file is like:
<?php
require('i_PDOConnection.php');
$query = "SELECT empFName + ' ' + empLName as [empName], empTitle FROM tbl_CouncilStaff WHERE active = 1 AND display = 1 AND (empFName LIKE '%".$search."%' OR empLName LIKE '%".$search."%') ORDER BY empLName";
$stmt = $dbh->prepare($query);
$stmt->execute();
$data = $stmt->fetchAll();
foreach ($data as $row) {
    $empName[] = $row['empName'];
    $empTitle[] = $row['empTitle'];
}
 $arrData = array($empName,$empTitle);
 echo json_encode( $arrData );
?>

Open in new window


The code is working if I only use the $empName or $empTitle array and encode that ($data = $empTitle or $data=$empName.  

However making an array of both arrays causes the empName box to return two blank lines instead of any names or titles when I type.  I get that, but I don't know what to do about it to access the underlying data and have the names list in text box one and populate the employee title to text box two upon a selection.

As always, thanks in advance for any help offered.
0

PHP

118K

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.