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
Industry Leaders: We Want Your Opinion!
Industry Leaders: 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!

my Sql

Following Query = "SELECT `user_id` FROM " . T_USERS . " WHERE `user_id` IN (SELECT `following_id` FROM " . T_FOLLOWERS . " WHERE `follower_id` = {$user_id} AND `following_id` <> {$user_id} AND `active` = '1') AND `active` = '1' ";

Follower Query = " SELECT `user_id` FROM " . T_USERS . " WHERE `user_id` IN (SELECT `follower_id` FROM " . T_FOLLOWERS . " WHERE `follower_id` <> {$user_id} AND `following_id` = {$user_id} AND `active` = '1') AND `active` = '1'";

But i can not get Mutual Friends
sql.jpg
0
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
I am used to using procedural php and jQuery/ajax. Here is a simple example of how I would usually use them together.

Let's say I have a page that just has an input field.

<input type="text" name="name" id="name">

Open in new window


Then to keep it simple, I have some jQuery at the bottom of the page:

// code here to trigger the ajax call on button click/form submit etc.
		var form = $( "#loginForm" ).serialize();	
			$.ajax({
				url: 'functions/some-file.php',
				type: 'POST',
				dataType: 'json',
				data: form,
				beforeSend: function() {
					$( "#login" ).hide();
					$( ".spinner" ).html("<img src='img/spinner.gif'>");
				},
			})
                     // .done and .fail go here

Open in new window


The some-file.php file would look something like:

<?php

if($_POST) {

	$response = array();
	$message = "";

if(empty($_POST['name'])) {
		
		$message .= "Name required";
	}

if($message) {
	
		$response['success'] = false;
		$response['message'] = $message;
	
	} else {

                // add data to database
                $response['success'] = true;
		$response['message'] = "Success";
		
	}
	
	echo json_encode($response);
}

Open in new window


This works fine. I have a basic MVC framework that I built from scratch using only php based on a course I did (no templating engines or anything, just plain php) and don't know how to do the above in MVC.

At this point I have the view and the controller. I am not onto the model yet. At this point I have a form with email and password fields and I am just trying to do the validation. Here I am just checking if the email field is empty or not to keep it simple.

In my controller I just have:

      
public function login() {
		
		if($_POST) {
			
			
			$data = [
				
				'email' => trim($_POST['email']),
				'email_err' => '' 
			];
			
			if(empty($_POST['email'])) {
				
				$data['email_err'] = 'Email required';
			}
			
			if(empty($data['email_err'])) {
				
				//call login model
				

			} else {
				
				$this->view('users/login', $data);
			}
			
		} else {
			
			$data = [
				
				'email' => '',
				'email_err' => ''
			];
			
			$this->view('users/login', $data);
		}
	}

Open in new window


And my view:

<form action="<?php echo URLROOT;?>/users/login" method="post">
	<input class="form-email" type="email" placeholder="Email Address" name="email" autocomplete="off">
	<input class="form-password" type="password" placeholder="Password" name="password">
	<input class="login-btn btn-filled" id="login" type="submit" value="Login">
	<div class="spinner"></div>
	<input type="hidden" name="form_token" id="form_token" value="<?php //echo make_form_token(); ?>">
	<input type="text" name="some-field" style="display:none;">
</form>
<div class="alert alert-danger">

Open in new window


So, the question is, how on earth do I make the ajax call using the controller and send the data to the model?
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
Hello Experts,

We have a web system running from a Windows 2012 R2 server.  The server has 128GB RAM and 2 x 16 core xeon processors.

I am a network administrator but my in depth knowledge of fine configuration of IIS is limited.

We use PHP 5.6 and have about 300 customers logging into the system and updating records.  At least once a week, the website goes down and is only brought back online after a command prompt 'iisreset' action is performed.  The developers are currently testing the system with PHP 7.1 before we switch over from 5.6.  The errors in the Event Viewer do not correspond to the website crash

My question is, are there more settings i need to change in IIS to make the website run better, application pool failover, etc

Any guidance is appreciated

Kind Regards

Andy
1
Hello Julian,

The php script that you gave me earlier was working perfectly till yesterday morning. But suddenly, The form is not being submitted and I am getting the following error after submitting the form. I asked my hosting provider and he said that they have not made any changes or up gradation. This is the error:

Could not execute: /usr/sbin/sendmail -t -i

Could you please tell me what could be the problem.

Regards
Saxena
0
Greetings again.

I have the following:

      <?php
	$conn=mysqli_connect("localhost","myuuser","mypass","mydb");
	 // Check connection
	 if (mysqli_connect_errno())
	   {
	   echo "Failed to connect to MySQL: " . mysqli_connect_error();
	}
	$select_query="Select pastorname, ministryname from xphias_clients";
	$select_query = mysqli_query( $conn,$select_query);
	echo "<select name='pastorsname' id='pastorsname' class='form-control'>";
	while ($rc=   mysqli_fetch_array($select_query) )
	{
	   echo "<option value='" .$rc[ministryname] . "'>" . $rc['pastorname'] . "</option>";
	}
	echo "</select>"; ?></td>
     <td><INPUT TYPE="TEXT" class="form-control" NAME="ministriesname" id='ministriesname' SIZE="16"></td>

     //JS
	<script type="text/javascript">
	$(document).ready(function(){
	    $('#pastorsname').change(function(){
	      var ministriesname = $(this).val();
	      $('#ministriesname').val(ministriesname);
	    });
     });
    </script>

Open in new window


On the server side, how do I grab the text of the dropdown list?

In other words, instead of grabbing the value of ministryname, I want to grab the value of pastorname in the following:

 . "'>" . $rc['pastorname'] . "</option>";]

Open in new window


Is it possible?

Thanks in advance
0
I have an API consisting of two files that takes a url from a user, processed it, and sends an array to another file to return XML data back to the user. My problem is that I do not know how to get the return data (if I were the user) and parse it. Using a browser, the XML will display fine. I am hoping there are PHP functions that will send the url and retrieve the result for parsing.
Here is an example of the url sent by the user:
http://www.domain.com/xmlapi.php?a=1&b=2&c=3

Open in new window

Those query vars are then processed, sent to another server, and an array of results is returned. I then create a query string from those results place that string into another query and send that to another file that returns the XML.
The query string looks like this:
XMLProcess.php?Q=Element1^Value|Element2^Value|ElementThree^Value ... etc.

Open in new window

That file looks like this
   $dom = new DOMDocument("1.0", 'utf-8');
   header ("Content-Type:text/xml");
   $QArray = explode('|',$_REQUEST[Q]);
   foreach($QArray as $value)
   {
      $x = explode('^',$value);
      $XMLItems[$x[0]] = $x[1];
   }
   $root = $dom->createElement("Requests");
   $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

As I say, this will display well-formatted xml in a browser, but is there a way to receive and parse this xml data with PHP?
Am I creating extra problems by having a secondary processing file (XMLProcess.php), rather than just including this XML creation code in the xmlapi.php file?

I'm trying to avoid using something like CURL or SOAP, if possible.
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
New feature and membership benefit!
LVL 11
New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

I had this question after viewing Populate PDF with Data from MySql Database Using Php.

I need to find a solution where you're able to use a PDF form to input data (into the PDF form) and write it directly to a MYSQL DB. It may sound simple but I'm not able to find a solution out there. The closest is something like HelloSign but that's overkill for our simple requirement.
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
I have my php files on an IIS 8 server.
I put a session_start on the top of the page.

My code was working fine. I moved it to a new folder. It worked for 5 minutes, and then I got this error:

Warning: session_start(): open(C:\Windows\temp\sess_69voc1ru64hq9ipmqm8llpdqn4, O_RDWR) failed: Invalid argument (22) in \\19******de.php on line 3
Success
Warning: Unknown: open(C:\Windows\temp\sess_69voc1ru64hq9ipmqm8llpdqn4, O_RDWR) failed: Invalid argument (22) in Unknown on line 0

Warning: Unknown: Failed to write session data (files). Please verify that the current setting of session.save_path is correct (C:\Windows\temp) in Unknown on line 0

Open in new window


I set up a new folder, tried it there and it worked, and then 5 minutes later it started erroring again.

what can I do to make it work?
0
Enroll in this month’s featured course to get 19+ hours of PHP, MySQL, and CakePHP MVC framework training.
1
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
hello,
i want to convert opencart tpl files into twig file.
any one give me better solution
0
I have xampp downloaded, but I still can't view any of the php files on dreamweaver.  I configured it so it would run, but still having no luck.  Any suggestions?? Thanks
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
What does it mean to be "Always On"?
LVL 5
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

I have a standard HTML form with a jQuery onclick function which does several processes, depending on the submit. All functions are working fine, but the simplest section of this jQuery code just does a normal submit. However, this form data on this submit goes to a PDF creation file and needs to be URLencoded. I cannot figure out how to do this without listing every field in a very long form. I've searched the Web but not found an answer. Seems there should be a simple way to url encode this submit. Here is the current submit function:
<script>
    $(document).on('click', '.ClickCheck', function(e)
    {
        var Form = $('#TheForm');
        $(Form).attr('action', './PDFResultPage.php');
        $(Form).submit();
    });
</script>

Open in new window

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
Hello experts,
I have the following situation,

I have a pc windows10 and I have a Macbook pro

I have installed Google drive on the pc and installed wamp and synced 2 folders in the www folder of wamp located in C:

As I'm taking my laptop from a room to another I installed Google drive on this laptop but the folder i chose to sync from pc couldn't be downloaded into my laptop

I'm not sure how to setup this properly as mamp path is different and wamp path is also a different location and my google drive is only showing files not folders...

any idea?
0
On change event of "select" element i want to use MainPage.php to reload an image.
I have next code, which is not  working;
js  code
function imageRefreshOnSelectChange(){        
$.ajax({
  type: 'POST',
  url:'/wp-content/themes/net/MainPage.php'
});
}

Open in new window

 

header.php
<body>
    <?php include_once("net/pageTop.php");?>
    <?php include_once("net/MainPage.php");?>
    <?php include_once("net/pageBottom.php");?>
</body>

Open in new window



MainPage.php
<?php
...............
............
 $users=..........;
?>
<div class="right" id="usersWindowID">
        <p><?php echo $users ?></p>              
    </div>

Open in new window



Is it possible to tell from the code i have provided what am i doing wrong?
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
<form name="submit_form" action="./uploads/submit.inc.php" method="POST">
                  <div class="wrapper">
               <code id="ace-editorid" name="code_editor" contenteditable>
                     Your Code Here
               </code>
               <textarea name="newTextArea" id="newTextArea" style="display: none;"></textarea>
      </div>
          <script type="text/javascript">
                document.getElementById("ace-editorid").oninput = function() {
                  document.getElementById("newTextArea").innerHTML = document.getElementById("ace-editorid").innerHTML;
            }
          </script>
          <script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script>
          <script src='http://cdnjs.cloudflare.com/ajax/libs/ace/1.1.3/ace.js'></script>
          <script  src="./css/script.js"></script>
          Type the Problem ID: <input type="text" name="probId">
          <input type="submit" name="b_code_submit" class="submit_query">
</form>

In this code what i want to do is that i'm taking code input from user in       `<code>` tag and copying it to the `<newTextArea>` tag, so that i can use it in my another php file using POST method, but when i'm doing it, i'm getting blank text.
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.