Go Premium for a chance to win a PS4. Enter to Win

x

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

How can i print out the value without using echo statement? I use it like this

<?php echo $value ?>
I know that there is another usage but i can not remember it
0
Keep up with what's happening at Experts Exchange!
LVL 11
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

see this code:
$yd = 293;
// check box for assemply type
if ($_SESSION['asstyp'] == "RP" || $_SESSION['asstyp'] == "RPD") {
	$yd = 273;
}
$pdf->SetFont('Arial','B',10);
if ($_SESSION['asstyp'] == "RP") {
		$xd = 218;
}
if ($_SESSION['asstyp'] == "RPD") {
		$xd = 295;
}
if ($_SESSION['asstyp'] == "DCV") {
		$xd = 210;
}
if ($_SESSION['asstyp'] == "DCD") {
		$xd = 225;
}
//echo "yd = " . $yd . "<br>";
if ($_SESSION['asstyp'] != "PVB" && $_SESSION['asstyp'] != "SVB") {
	$pdf->SetXY($xd,$yd);	
	$pdf->Cell(20,20,"X",0,0);
}	

Open in new window


When the value of $_SESSION['asstyp'] = "RP", it works fine.

In the case of "RPD", it ignores the $xp setting.

In all the other cases, it sets $yp to something like 333 (I can't tell exactly) but does the $xp about right.

I had a php switch; when all this started I changed to the bunch of if's because I was sure the switch was not working. The switch gave the EXACT same result.

I realize it has to be something obvious that I cannot see.

If you know fpdf that would help. I am trying to overlay data on an existing image background.

Thank you
0
Dear Experts,

which one is more secure to post data for html form?

<form  method="post" >

or

<form  method="post" enctype="multipart/form-data" >

or anything you suggest?

I use PHP and HTML
0
What could be the issue with my script? When I send some variables from JavaScript to PHP, I want PHP to pick the variables with $_GET from my URL query string, but PHP is returning "undefined variable" Below is my scripts:

JavaScript:
function callstats(stats) {
    var stats_id = stats.parentNode.firstElementChild;
    post_tag = stats_id.id.split('.')[0];
    post_id = stats_id.id.split('.')[1];
    //alert(post_tag);
    window.location = "http://localhost:8080/reminderapp/callstats.php?tag=" + post_tag + "&id=" + post_id;
}

Open in new window

NOTE: the alert(post_tag) in line 5 above returns the correct value.

PHP:
if(isset($_GET['post_tag'])) {
    $tag = lcfirst(($_GET['post_tag']));
    $id = ($_GET['post_id']);
}
var_dump($id);
var_dump($tag);

Open in new window


NOTE: My browser also showed correct URL with correct 'tag' and 'id', but var_dump on variable id and tag in PHP is still returning 'NULL'
Below is my browser URL after the javascript is fired:
http://localhost:8080/reminderapp/callstats.php?tag=Once&id=235
The browser URL has correct tag and Id as supplied by the JavaScript, but PHP is not 'GETing' it.
Please help me, why is this?
0
Hello, so I'm trying to mirror some website from my LAMP server to my Windows 10 PC.
I am using WAMP server to do this but I have huge problems with permissions.

Apache can't seem to write stuff anywhere. The service runs as local system and the SYSTEM user has full control. I also tried giving EVERYONE full control, it still doesn't work. I keep getting errors like this:

Warning: error_log(../xxxxxxxxxxx/00000b015e503ae39081e38d06f1652e822b20171116.log): failed to open stream: Permission denied in B:\Siti\xxxxxxxxx\xxx.php on line 708

Open in new window


I also tried running Apache as a local administrator, still no go.

There must be a way to make this work. I have a CentOS vm on and I could use that, but it would be handier for me to go full local.
Also, I can't stand things not working.
0
Hi experts,
I need to reproduce this query in CodeIgniter, using ActiveRecord.  I've got very close but CI is putting backquotes where they are not wanted (the yellow-highlighted ones).
Here's the query and CI's interpretation of it...
query as interpreted by CIand here's the code I used to get it.  Part of this stems from CI's lack of support for UNION.
public function get_squad ($fixture_id, $side)
	{	
		$team_clause = 'X';
		if($side=='1') {$team_clause = ' p_1sts ';}
		if($side=='2') {$team_clause = ' p_2nds ';}
		if($side=='3') {$team_clause = ' p_3rds ';}
		if($side=='4') {$team_clause = ' p_4ths ';}
		if($side=='S') {$team_clause = ' p_sundays ';}
		if($side=='T') {$team_clause = ' p_sundays_res ';}
		if($side=='V') {$team_clause = ' p_young_vets ';}
		if($side=='W') {$team_clause = ' p_senior_vets ';}
		
		$this->db->select('first_name, surname, id AS "player_id", "Y" AS "player_picked", fp_keeper AS "keeper", fp_owes_subs AS "subs", fp_if_fit AS "fit", fp_if_available AS "available"');
		$this->db->from('fixtures_players');
		$this->db->join('players_members', 'fp_player_id = id', 'INNER');
		$this->db->where('fp_fixture_id', $fixture_id);
		$this->db->group_by(array('first_name', 'surname'));
		$first_half_inner_union = $this->db->get_compiled_select(); 		
		
		$this->db->select('first_name, surname, id AS "player_id", "N" AS "player_picked", "" AS "keeper", "" AS "subs", "" AS "fit", "" AS "available"');
		$this->db->from('players_members');
		

Open in new window

0
Although there is a fair amount of data, I written a fairly basic API which I need to return in XML format. What I need to know is how to send this data back in an XML file. The code below displays a well-formed XML to the browser.
After preliminary processing, a string is sent to the XML processing file shown below.
Elements are delimited with |, while Key/values are delimited with ^.
<?php
   $dom = new DOMDocument("1.0", 'utf-8');
   header ("Content-Type:text/xml");
   $QArray = explode('|',$_REQUEST[Q]); // separate elements
   foreach($QArray as $value) // create key/value pairs
   {
      $x = explode('^',$value);
      $XMLItems[$x[0]] = $x[1];
   }

   $root = $dom->createElement("RequestResult");
   $dom->appendChild($root);
   foreach($XMLItems as $key => $value)
   {
      $key = $dom->createElement($key);
      $root->appendChild($key);
      $variable = $dom->createTextNode($value);
      $key->appendChild($variable);
   }
   echo $dom->saveXML();
?>

Open in new window

0
See this code:
$piece1 = $test;
$piece2 = "";
$piece3 = "";
$ln = strlen($test);
if ($ln > 84) {

	$arrayWords = explode(' ', $test);

// Max size of each line
	$maxLineLength = 84;

// Auxiliar counters, foreach will use them
	$currentLength = 0;
	$index = 0;

	foreach ($arrayWords as $word) {
    // +1 because the word will receive back the space in the end that it loses in explode()
		$wordLength = strlen($word) + 1;

		if (($currentLength + $wordLength) <= $maxLineLength) {
			$arrayOutput[$index] .= $word . ' ';

			$currentLength += $wordLength;
		} else {
			$index += 1;

			$currentLength = $wordLength;

			$arrayOutput[$index] = $word . ' ';
		}
	}
	$piece1 = $arrayOutput[0];
	$piece2 = $arrayOutput[1];
	$piece3 = $arrayOutput[2];
}	

Open in new window


This works perfectly, except I need a variation where I can limit the FIRST line ($arrayOutput[0]) to 84 & the subsequent lines to 94. See attached image for visual of this need. The text is printed using a pdf generator on an existing form image (with the word Remarks & the lines.)

How can I do this?

Thank you
Capture.JPG
0
I was wondering if it was possible to sort one particular key in a mutli-dimensional array without disrupting the order of the other keys? I'm going to to be doing a complex "ORDER BY" when selecting my table with the mysql query, however there's a limitation on how much I can do, and want to try to do the rest with the resulting array in PHP without destroying the sort already present. To elaborate, I'm unable to implement a "natural sort" on varchar fields with an "ORDER BY" -  I've scoured the net and tried multiple ideas, but nothing I've tried to apply a natural-sort-equivalent has worked, so I thought that could be the job of PHP.  A snippet of my resulting array from my table looks like this (the real one is quite a bit larger with a lot more keys):

    [1422] => Array
        (
            [pagename] => item000617
            [category] => Promotional Music
            [subcategory] => Compilations
            [subsubcat] => 
            [title] => Warner Music Taiwan - January 1992 
            [country_full] => Taiwan
            [newyear] => 1992
            [format] => CD
        )

    [1423] => Array
        (
            [pagename] => item000898
            [category] => Promotional Music
            [subcategory] => Compilations
            [subsubcat] => 
            [title] => Warner Music Taiwan - September 1999
            [country_full] => Taiwan
            [newyear] => 1999
            [format] => CD
        )

    [1424] => Array
        (
   

Open in new window

0
<file path="catalog/view/theme/*/template/checkout/payment_method.twig">
<operation>
<search><![CDATA[{% for payment_method in payment_methods %}]]></search>
<add position="after"><![CDATA[
{% if payment_method.code == cod %}
{% set  cost= '-'.cod_fee_fee %}
{% endif %}
]]></add>
</operation>
</file>
<file path="catalog/view/theme/*/template/checkout/payment_method.twig">
<operation>
<search><![CDATA[{{ payment_method.title }}]]></search>
<add position="replace"><![CDATA[ {{ payment_method.title }}{{ cost }}]]></add>
</operation>
</file>
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.

This is really strange folks. I've never run into anything like this before. Can you help?
Thanks,
Sas

MySQL query is mistaking the column name for the value!!! What's wrong?

The value of $apt is 12GH
The column name is 'apt'.
So, why on earth is "mysql_error())" giving me the following error?

L-83
Error: Failed at saving data: WHERE apt =12GH
Unknown column '12GH' in 'where clause'

Here's the query
$UPDATE_db="UPDATE `$S_TableName` SET 
`admin_f_name`='$admin_f_name',  `admin_m_name`='$admin_m_name', `admin_l_name`='$admin_l_name'
WHERE apt =`$apt`"; 
		mysql_query($UPDATE_db) or die("L-83<BR/>
		<font color=RED>Error: Failed at saving data: WHERE apt =$apt
 		" . mysql_error());

mysql_close();

Open in new window

0
I have this a main site that logins users to their profiles, How can I make it that if a user is logged in into the main site, then they are automatically logged in to the secondary site (whole other site & server). Do I have to use file get contents?
0
Hello Experts currently our website requires CAC or PKI to get to login screen.  Is there anyway to capture CAC Id's as users login?  Rather than having 1500 users send us their CAC Id's & manually tied to their account?
0
Dear Experts,

I assign the value empty. And create an if statement it works, but it give an error.

Error message is : Notice: Undefined index: ....

$durum="";

if ($_POST["durum"]) {  // it gives error here..
	
$durum = test_input($_POST["durum"]);

Open in new window

0
Hi experts,

I need to change an array from this
array to alter
to this:

Array
(
     [KCL P] => Kent county League Premier division
     [IRC 1] => Bill Manklow Inter Regional Challenge Cup 1st round
     [IRC 2] => Bill Manklow Inter Regional Challenge Cup 2nd round
)

Any help appreciated.

Col
0
I have a PHP webpage that captures the username of the person connecting to it.

I now need to do a lookup in Active Directory to get the email address (SecurityPincipal.sAMAccountName)

I have had some success with the below code, in it will bind successfully with LDAP but does not return anything

<?php

//using ldap bind anonymously

// connect to ldap server
$ldapconn = ldap_connect("global.tesco.org")
    or die("Could not connect to LDAP server.");

if ($ldapconn) {

    // binding anonymously
    $ldapbind = ldap_bind($ldapconn);

    if ($ldapbind) {
        echo "LDAP bind anonymous successful...";

        ldap_set_option($ldapconn, LDAP_OPT_PROTOCOL_VERSION,3);
        ldap_set_option($ldapconn, LDAP_OPT_REFERRALS,0);

        $dn = "CN=Users,DC=name,DC=name,DC=org"; 
        $filter="(sAMAccountName=username)";
        $justthese = array("ou", "sn", "givenname", "mail");

        $sr=ldap_search($ldapconn, $dn, $filter, $justthese);

        $info = ldap_get_entries($ldapconn, $sr);

        echo $info["count"]." entries returned\n";

    } else {
        echo "LDAP bind anonymous failed...";
    }
}
?>

Open in new window

0
Hello,

I am new to php. I have created an html form where the user selects any one option from the radio button. Every option has a price that user will be paying if he orders. What I want is to send that price to the user as auto generated mail when the user submits the form. My html is as follows:

<input type="radio" name="grade"  class="form-control" required><img src="images/grade_2.png" alt="no image">&nbsp;
<input type="radio" name="grade"  class="form-control" required><img src="images/grade_3.png" alt="no image">&nbsp;
<input type="radio" name="grade"  class="form-control" required><img src="images/grade_4.png" alt="no image">&nbsp;
<input type="radio" name="grade"  class="form-control" required><img src="images/grade_5.png" alt="no image">&nbsp;
<input type="radio" name="grade"  class="form-control" required><img src="images/grade_6.png" alt="no image">&nbsp;
<input type="radio" name="grade"  class="form-control" required><img src="images/grade_7.png" alt="no image">

For example, if the user selects the third option and the price is 5000, then the user gets the mail that "The cost for the option you have selected is 5000."

I am not been able to write the php code for this. Please help me. Also I want to send these images to the receiver when the user submits the form. How can I do this?

Thanks.

Regards
Saxena
0
I have a code to generate a PDF and then attach it in a PHP mail script.
The PDf comes through just fine when I open gmail in my browser.

If I open my gmail account through outlook, I see the little attachment symbol, but the email comes through totally blank and I can't access the PDF.
Is there something else I am supposed to change?


    $name        = "Devorah";
    $email       = "ffrid@****";
    $to          = "$name <$email>";
    $from        = "info@*****";
    $subject     = "Application information";
    $mainMessage = "Hi, here's the file.";
    $fileatt     = "application.pdf";
    $fileatttype = "application/pdf";
    $fileattname =  $_POST['lastName'] . "_" . $id .".pdf";
    $headers = "From: $from";

    // File
    $file = fopen($fileatt, 'rb');
    $data = fread($file, filesize($fileatt));
    fclose($file);
   
    // This attaches the file
    $semi_rand     = md5(time());
    $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
    $headers      .= "\nMIME-Version: 1.0\n" .
    "Content-Type: multipart/mixed;\n" .
    " boundary=\"{$mime_boundary}\"";
    $message = "This is a multi-part message in MIME format.\n\n" .
    "-{$mime_boundary}\n" .
    "Content-Type: text/plain; charset=\"iso-8859-1\n" .
    "Content-Transfer-Encoding: 7bit\n\n" .
    $mainMessage  . "\n\n";
       
    $data = chunk_split(base64_encode($data));
    $message .= "--{$mime_boundary}\n" .
    "Content-Type: {$fileatttype};\n" .
   …
0
I'm able to run select statements to my sql server
 $link = mssql_connect('10.10.50.xxx', 'userx', 'pasx');

if (!$link)
    die('Unable to connect!');
if (!mssql_select_db('Camstat', $link))
    die('Unable to select database!');

$result = mssql_query("INSERT INTO [DB1].[dbo].[Footage_Age] ([DVRId] ,[CameraId]  ,[Last_Date] ) VALUES    (135456,525685,'2013-08-27')");

while ($row = mssql_fetch_array($result)) {
    var_dump($row);
}

mssql_free_result($result);

Open in new window


But I'm unable to run inserts into the DB.  The user has write permission to the sql db.  I've tried a lot of examples I've found on the net but with no success.
0
Concerto's Cloud Advisory Services
LVL 5
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

I have godaddy VPS. Its windows server with plesk. Two websites are hosted. for one of them email function works for the other one it gives 503 error, smtp authentication, This mail server requires authentication when attempting to send to a non-local e-mail address.
0
I have a VB6 Application  and a PHP application on 2 different PCs

I want to take a PHP script  (attached) and run it within the Visual Basic Code

My first thought was that since the PHP Script feels like an HTML  file

there may be a  way  to run it with the Shell command

Can any one help out with this

I attach the PHP Script

Thanks

O.A.  Oluwole
index.php
0
Could anyone here show me some examples on how I'd interface with this Spark API using PHP (to pull in MLS data)?  

http://sparkplatform.com/docs/overview/api

Thanks,
- Yvan
0
Hello,  I have a custom shortcode that calls an API.  Works great, but I'd like to add a parameter to it in order to tweak the output a bit.  We already have one paramter, but the second one I'd like to add would be more along the lines of an array, so I need some tips.   The shortcode calls an API that pulls events from a calendar database.   Below are the lines of code related to this (not the full script of course):
function cal_events_shortcode($params = array()) 
{
extract(shortcode_atts(array("limit" => 5), $params));
$eventTypes = array (3,7);
...
}

Open in new window


This shortcode is called by inserting  [cal_events limit="4"] into a Wordpress page.   If no value is passed for "limit", it defaults to 5.  It then pulls events with the event types of 3 and 7, based on the hard-coded value for "eventTypes".

What I want to do is accept the values of "3, 7" as variables that are passed by the shortcode call and then inserted into the $eventTypes variable.    So, what would the "extract(shortcode_atts..." line of code look like if also accepting the values that need to go into $eventTypes array?

I imagine this is pretty simple, but I don't call myself a programmer.

Thanks for any tips!
0
I have installed my app in a Bitnami Lamp stack subdirectory off of the root.  When I try to access it using abc.com/sub it doesn't work.  But if I put in a test program in abc.com/abc.php it works fine.   I need this stack to have 4 sites on it.  

How do I set it up so I can 4 vhosts?

The first vhost is only a test and isn't propogated.  The rest will be added after the first vhost is completed.

Thanks,
0
Hi Experts,

I just upgraded from PHP 5.6 to 7.1

On PHP 5.6 when I had a PHP error mid-page it still showed my elements that came before the error, such as my print_r  output, which helped in troubleshooting, but now with PHP 7.1 it hides everything and shows the error on a blank page.

How can I show the prior elements?

Thanks
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.