[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x

PHP

120K

Solutions

33K

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

$getContactIDs = array();

                $stmt = new Database();

                
                $query = "SELECT ID FROM TXT2GIVE_CONTACTS WHERE ORGANISATION_ID = :orgID";
                $stmt->query($query);
                $stmt->bind(':orgID', $orgId);
                $stmt->execute();
                $result = $stmt->all();

                foreach($result as $getContactIDFromOrg){
                        $getChannelIDs['ID'] = $getContactIDFromOrg['ID'];
                }
                $testArr = $getChannelIDs['ID'];

Open in new window



this is suppose to go into each row and assign each result to an array but it only taking the last ?

what going on ?
0
CompTIA Security+
LVL 12
CompTIA Security+

Learn the essential functions of CompTIA Security+, which establishes the core knowledge required of any cybersecurity role and leads professionals into intermediate-level cybersecurity jobs.

I am using PHP to search a LDAP member of list to see if a user is a member of a group "GG-UK-Pink-Stores 2136 StoreManager" and then if they are a member pull out the four digit store number.

It works however it doesnt seem to check for the StoreManager and bring back anything similar.

// *****************************************************
// Searches for the Key of Store Manager within the array.
// *****************************************************
      $keysval = ['StoreManager'];
      foreach($ldapGroups[0]['memberof'] as $k => $v) {
        if ($k === 'count') continue;
        echo $v . "<br>";
        if (preg_match('/.*? (\d\d\d\d) .*/', $v, $match)) {
            $keyval[$match[1]] = true;
        }
        
      }
      $retailOutletNumbers = array_keys($keyval)
0
Hello Experts!

Help me look at the following function, it's not resizing other formats (png, gif) but jpg/jpeg.

If you have other method(s) of resizing images before, during or after upload, please share with me.

function resize($in_file, $out_file, $new_width, $new_height=FALSE) 
{ 
$image = null; 
$extension = strtolower(strrchr($in_file, '.')); 
switch($extension)
{
	case '.jpg':
	case '.jpeg':
	$image = @imagecreatefromjpeg($in_file);
	break;
	case '.gif':
	$image = @imagecreatefromgif($in_file);
	break;
	case '.png':
	$image = @imagecreatefrompng($in_file);
	break;
	default:
	$image = false;
	break;
}
if(!$image || !is_resource($image)) return false;


$width = imagesx($image); 
$height = imagesy($image); 
if($new_height === FALSE) 
{ 
$new_height = (int)(($height * $new_width) / $width); 
} 

$new_image = imagecreatetruecolor($new_width, $new_height);
imagecopyresampled($new_image, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height); 

$ret = imagejpeg($new_image, $out_file, 80); 

imagedestroy($new_image); 
imagedestroy($image); 

return $ret; 
}

Open in new window


Thank you in advance.
0
<?php
    include('SupportTicketsConnect.php');
	$id=$_GET['id'];
	$result = $db->prepare("SELECT * FROM support WHERE sup_id= :userid");
	$result->bindParam(':userid', $id);
	$result->execute();
	for($i=0; $row = $result->fetch(); $i++){
    ?>

<?php  if (isset($row['sup_addcom1'])) {
<label>Additional Comments  :</label>
<textarea name="p_new_3" type="text" class="commenttext" ><?php echo $row['sup_addcom1']; ?></textarea><br/><br />
} 
    ?>

<?php
	}
?>

Open in new window


The above code gives a page error
Can someone please explain why
0
I have our WordPress site hosted on AWS and on relatively small VM's and low power RDS database.  This is usually enough power for our use (this is internally accessed Wordpress Site). However, on occasion (couple to several times a day) my RDS database will spike the CPU. The connections rise up as well indicating multiple large queries are being submitted. At times, this behavior will extend for several minutes and at times it will cause the search function, or the entire site to become unresponsive. I have discussed this with AWS support and they believe that just throwing more compute power to it, isn't going to really help.

I have narrowed this down to an extent as our users search on phone numbers or names and such. If they get impatient and hit the enter key several times after entering a search query, this causes subsequent search queries to the database. The search usually has to go through 8million + metadata records to compile results, so you can see how this is an issue.
I believe we may have the same issue on other types of submissions as well, but a fix on this one will get me a head start.

What I need for Wordpress, is a code snippet that disables submission of subsequent entries once the first one has fired and the page is waiting for the results before it reloads to a results page.

Thanks for your help!
0
Dear Experts,
I use PHP and Mysql,
how can I count the rows one by one when I output the data of each row?
for example if 15 rows came out as result of mysql query, I want to write it infront of every row that I fetch.
1. row, 2. row, 3. row, 4. row...

$sql = "SELECT * FROM mytable WHERE mpt='0' order by id DESC"; 

$result = $conn->query($sql);

if ($result->num_rows > 0) {


echo "
<div class='table-responsive'>
<table class='table table-striped table-bordered'>
<tr>
<th>number</th>
<th>id</th>

</tr>";


    while($row = $result->fetch_assoc()) {
        	
	$_key= $row["id"];	
	
	echo "<tr> 
	
	<td> $_key </td>
	
	
	</tr>";

			}
echo "</table></div>";

Open in new window


is it possible to do something like that? thank you
1
Hello Experts!

I normally populate DataTable with the following combination. When a button is clicked, the table is populated through AJAX call as long as there's at least 1 row of data. But if there're no data in the table from MySQL, nothing happens. So, I want a message to return when there's no data coming from database.

Please help me manipulate this:

<?php 

require_once '../.../db_connection.php';

$stmt = $conn->prepare( "SELECT ... FROM ... WHERE ..." );
$stmt->bind_param( "ssssi", $_POST['session'], $_POST['term'], $_POST['class'], $_POST['subject'], $_POST['limit'] );
$stmt->execute();

$assessment = $stmt->get_result()->fetch_all(MYSQLI_ASSOC);
die( json_encode($assessment) );
?>

Open in new window



Here is my AJAX:
$('#loadStudents').click(function() {
   $.ajax({
   method : 'post',
   url : '../data/ass1_Data',
   data : { session : $('#session').val(), term : $('#term').val(), class : $('#c_taught').val(), subject : $('#s_taught').val(), limit : $('#process_limit').val(), },
   dataType : 'json',
   }).done(function(data) {
      myDt.clear().draw();
      myDt.rows.add(data).draw();
   });
});

Open in new window


Thank you in advance.
0
Source page:
<?php
    include('SupportTicketsConnect.php');
	$id=$_GET['id'];
	$result = $db->prepare("SELECT * FROM support WHERE sup_id= :userid");
	$result->bindParam(':userid', $id);
	$result->execute();
	for($i=0; $row = $result->fetch(); $i++){
    ?>
   
<form action="SupportTicketsUpdate.php" method="post" name="dataentry">
    
   <?php
    $ticketnumber = rand(1, 1000000);
    
 ?>
   
    <input type="hidden" name="ticketnum" value="<?php echo $id+1;?>"/>
    Ticket Number: #<?php echo $id+1;?><br /><br />
    
    <input type="hidden" name="supid" value="<?php echo $row['sup_id']; ?>" />
    
    <Label>Status of Ticket :&nbsp;&nbsp;</Label><input type="radio" name="radnew" value="New Ticket" <?php if ($row['radnew']== 'New Ticket') echo "checked='checked'"; ?>>&nbsp;New Ticket</input>
    &nbsp;<input type="radio" name="radnew" value="nocategory" <?php if ($row['radnew']== 'nocategory') echo "checked='checked'"; ?>>&nbsp;No Category</input><br /><br />
<Label>Origin of Ticket :&nbsp;&nbsp;</Label><input type="checkbox" name="emailsupport" value="emailsupport" <?php if ($row['chkemail']== 'emailsupport') echo "checked='checked'"; ?> />&nbsp;email to support
    &nbsp;<input type="checkbox" name="phonesupport" value="phonesupport" <?php if ($row['chkphone']== 'phonesupport') echo "checked='checked'"; ?> />&nbsp;Phone to support
    &nbsp;<input type="checkbox" name="smssupport" value="smssupport" <?php if ($row['chksms']== 'smssupport') echo 

Open in new window

0
 <Label>Status of Ticket :&nbsp;&nbsp;</Label><input type="radio" name="radnew" value="New Ticket">&nbsp;New Ticket</input>&nbsp;<input type="radio" name="radnew" value="nocategory">&nbsp;No Category</input><br /><br />
<Label>Origin of Ticket :&nbsp;&nbsp;</Label><input type="checkbox" name="emailsupport" value="emailsupport" />&nbsp;email to support&nbsp;<input type="checkbox" name="phonesupport" value="phonesupport" />&nbsp;Phone to support&nbsp;<input type="checkbox" name="smssupport" value="smssupport" />&nbsp;SMS to support&nbsp;<input type="checkbox" name="projectsupport" value="projectsupport" />&nbsp;Project work<br /><br />

Open in new window


I have the above code which is on a php page reporting database results
I need to be able to have the various radio and check boxes reflect that they have / have not got a value in the database and appear to be checked / unchecked if this is true / false
Can someone please give me a pointer on how to do it
0
Hello Experts!

Please why am I getting
Notice: Undefined index: subject in C:\...\createTable.php on line 6
?
NOTE: I can populate the table using DataTable but I don't want to us DataTable for this. If you know how I can do populate HTML Table using AJAX, please help.
HTML Form:
<form method="post" id="enrollmentForm" action="">
   <div class=" form-group center">
      <input type="hidden" name="session" id="session" value="<?= $default_session ?>">
      <input type="hidden" name="term" id="term" value="<?= $default_term ?>">
         <select name="c_taught" id="c_taught">
	   <option value="">Select Class...</option>
	   <?php echo fill_class_box($conn); ?>
	</select>

       <select name="s_taught" id="s_taught">
	<option value="">Select Subject...</option>
	<?php echo fill_subject_box($conn); ?>
       </select>
   </div>
   <div class="form-group center">
      <button type="button" name="loadStudents" id="loadStudents" class="btn btn-sm btn-primary btn-white btn-round">
         <i class="ace-icon fa fa-refresh bigger-150 middle orange2"></i>
         <span class="bigger-110"> Load Students</span>
      </button>
   </div>
</form>

Open in new window


My Ajax:
$(document).ready(function(){
  $("#loadStudents").click(function(){
    //disable the submit button
    $(this).attr('disabled','true');$(this).css('cursor','not-allowed');$(this).html('Processing');
    $.ajax({
      method : 'post',
      url : 'createTable',
      data : { class : $('#c_taught').val(), subject : $('#s_taught').val() },
      data : 'json',
      success: function(data)
      {
      	$('#enrollTable').html(data);
        //enable the submit button
        $('#loadStudents').css('cursor','pointer');$('#loadStudents').html('Submit');$('#loadStudents').removeAttr('disabled');
      },
      
    }); 
  });
});

Open in new window

Then, createTable.php
<?php
session_start();

include('../../db_connection.php');

$s_taught = $_POST['subject'];

$stmt = $conn->prepare( "SELECT ... WHERE Class_Name = ? AND ".$s_taught." = 0 AND Total_Subjects < 12 AND Status = 1 ORDER BY Roll_No" );
$stmt->bind_param( "s", $_POST['class'] );
$stmt->execute();
$students = $stmt->get_result();

$data = array();

while ( $student = $students->fetch_object() ):

    $data[] = array(
        "roll_no" => $student->Roll_No,
        "student_id" => $student->Student_ID,
        "student_name" => $student->Student_Name,
    );

endwhile;

$response = array(
    "data" => $data,
);

echo json_encode($response);
    
?>

Open in new window


Thank you  for your help.
0
OWASP: Forgery and Phishing
LVL 12
OWASP: Forgery and Phishing

Learn the techniques to avoid forgery and phishing attacks and the types of attacks an application or network may face.

When updating composer (sudo composer update), got the error below:
"- The requested PHP extension ext-memcached * is missing from your system. Install or enable PHP's memcached extension."
Tried very hard to install "PHP extension ext-memcached", but could not get anywhere.
Background: PHP 7.2.10-0ubuntu0.18.04.1 (cli) (built: Sep 13 2018 13:45:02) ( NTS ) on oracle VirtualBox v5.2.22.

Will any gurus shed some light to it?
0
Hello,
I need advice in securing an IIS server and PHP. I'll be uploading some php forms to be accessed through the browser and want to make sure they are secured.

IIS 8.5
PHP 7.0.7

Any help or advice would be appreciated.
Debra
0
Data is not loading from database on PHP page.

How can I troubleshoot data coming from the database?

The headers are displaying but no data underneath.

Database is SQL Server and it is using a Security Certificate.  I never added one before.
0
Searching though a JSON with php and jquery

I have some code that querys a DB with php and put the info in a json array here is my code


<html>
<head>
<title>Search</title>
<link rel="stylesheet" type="text/css" href="PrintMeThatLabel.css" />
<script src = "cookie.js" type="text/javascript"> </script>

<script src = "jquery-1.4.3.min.js" type="text/javascript"> </script>
<script src = "http://www.labelwriter.com/software/dls/sdk/js/DYMO.Label.Framework.3.0.js" type="text/javascript" charset="UTF-8"> </script>
<script src = "PrintMeThatLabel2.js" type="text/javascript" charset="UTF-8"> </script>
<style type=text/css>

.text {color: #000; font-family:Arial, Helvetica, sans-serif }
.head {color: #000; font-family:Arial, Helvetica, sans-serif }
.input {display:none;}



.tftable {font-size:12px;color:#333333;width:100%;border-width: 1px;border-color: #729ea5;border-collapse: collapse;}
.tftable th {font-size:12px;background-color:#acc8cc;border-width: 1px;padding: 8px;border-style: solid;border-color: #729ea5;text-align:left;}
.tftable tr {background-color:#d4e3e5;}
.tftable td {font-size:12px;border-width: 1px;padding: 8px;border-style: solid;border-color: #729ea5;}
.tftable tr:hover {background-color:#ffffff;}




</style>

</head>
<body>


    <div class=text align="center">

<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST" >

<span class=text>Enter Work Order #: </span>
<input type="text"  name="Work_Order" length="30"  value="">


<input 

Open in new window

0
Hi all, hoping one of you Gurus can assist please.

I have been using a payment system for many years but they have now changed one of their SOAP calls to an external URL. For the life of me I'm unable to connect without the following error:

"cannot be processed at the receiver, due to a ContractFilter mismatch at the EndpointDispatcher. This may be because of either a contract mismatch (mismatched Actions between sender and receiver) or a binding/security mismatch between the sender and the receiver. Check that sender and receiver have the same contract and the same binding (including security requirements, e.g. Message, Transport, None). "

these are the binding info from their App.config file if it helps
<bindings>
      <basicHttpBinding>
        <binding name="BasicHttpBinding_IPortalService">
          <!-- Transport security is only required when the portal service is running under https, for http this should be set to None -->
          <security mode="Transport" />
        </binding>
      </basicHttpBinding>
    </bindings>

Open in new window


I'm using PHP7 and have free run on the server to implement any of your suggestions. Previously I used cURL to simply create the SOAP XML, post if off and grab the response but having no luck here.

I cant post all the login details etc as it's payment and site specific but I'm after being initially able to at least connect to the SOAP URL below, and get a more valid error (for example, invalid user logon) etc.

Ok, here's the details:

https://pay360sc.e-paycapita.com/LivePayments242/PortalService.svc?wsdl

Action required is "Invoke" for which I believe the following should be the right XML to be sent:


Open in new window

0
I need to set up an IIS site (with PHP already installed) and import some forms to be accessed through the browser. It's been two years since I've used IIS and I have forgotten how to correctly set up a new website. (What port to use, making sure PHP is installed correctly using the PHP Manager, how to import the PHP forms created by one of our faculty members, make sure it is accessible on the web, etc.) Any help will be appreciated.

I don't think I set it up correctly - Hoping it will be accessible through: https://casweb.memphis.edu/msci-forms

Thanks,
Debra
0
I have a question about session variables:

I am using a session variable in my current website
I set the variable and use it to tag records inserted into a database from a php form
The website will be used by multiple users

The way the workflow works:
"User A" uses  a php form and sets the session variable from the form
Then they add records from the form into the database, with the session variable also being inserted into the database along with the other  record data

If, at the same time, another "User B"  is also using the same input form on the website and sets their own session variable, will there be a possibility of the new session variable accidentally being being used by "User A" instead of the one "User A" initially  set if "User A"  had not submitted their form data before "User B" had changed the session variable

If so, how can we avoid this
0
javaScript

I have a JSON array passed back to javaScript from a PHP / MS-SQL table extraction.   The table has 100 fields and 2,000 records so the JSON array has 100 "key":"value" pairs and 2,000 rows.

From this JSON array In javaScript, I would like to create another JSON array of all 2,000 rows from it, but with only 2 of its 100 key:value pairs. These two for example (ItemCode and ItemName):

{"ItemCode" : "1234567", "ItemName" : "Widget", "...." : "....", }, { .... }

How can I do that in javaScript?


Another question:

How can I do it being sure there are no duplicates of the 2 key:value pairs in the new array?
0
How would I compare two dates in the context of a loop?

I've got a table full of duplicates. I've been able to craft a foreach loop that accurately retrieves and displays duplicate values. But then, when I've got two duplicates to consider, I need to compare the dates and be able to give the user the opportunity to click a button that will delete the date that is the oldest.

I'm coming up short.

Here's what I've been trying:

<?php 
$current_date="";
foreach($current_list as $current)
{
	if($current['ssn']==$current['ssn'])
	{
		//I've got a duplicate
		if($current_date<>"")
		{
			if($current_date>strtotime($current['date'])
			{
				echo "a rebel yell";
			}
			else
			{
				echo "say nothing";
			}
		}
	}
$current_ssn=$current['ssn'];	
$current_date=strtotime($current['date']);
}
?>

Open in new window


It's not working. I've tried several different configurations and I'm ooen to suggests.

Any ideas?
0
Learn Ruby Fundamentals
LVL 12
Learn Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

I got the error when I installed php-mcrypt below:
sudo apt-get install php-mcrypt

----
sudo apt-get install php-mcrypt
Reading package lists... Done
Building dependency tree      
Reading state information... Done
Package php-mcrypt is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source

E: Package 'php-mcrypt' has no installation candidate
------

Background:
php -version
PHP 7.2.10-0ubuntu0.18.04.1 (cli) (built: Sep 13 2018 13:45:02) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
    with Zend OPcache v7.2.10-0ubuntu0.18.04.1, Copyright (c) 1999-2018, by Zend Technologies

in Oracle Virtualbox with Ubuntu. I saw someone installed it with
sudo apt-get install php7.0-mcrypt

However, no good for me.

Are any gurus shed some light to it. Greatly appreciate it.
0
This should not be hard unless I am doing it wrong . But I can't get it to echo "Go Upload";

Why ?

it does work if it finds another record  it  Echo "NO UPLOAD";





 while($row1= odbc_fetch_array($result_Search_before_uploading))
        {

		IF($row1["Serial No"] == $UsrSerialNumber)
    	{
    		Echo "NO UPLOAD";
    		Echo $row1["Serial No"]."<br>";
    		echo "user " . $UsrSerialNumber;

    	}Else
    	{
    		echo "Go Upload";
    	}


    	}

Open in new window

0
Using PHP I will have a form with about 50 fields on it.

One way to get to the page/form is to search by item ID.  If found the page will come up and the form will fill with existing data.

I would like to utilize the same page/form to "create" items.

What would be a good way to do this?

One way is to set each DB field to a variable and then populate the form using the variables.  For "new" items I would simply set the variables to defaults (usually blank or empty).

Is this about the only way?
1
How do I include a css file in my php code which is in another directory?
<?PHP
	ECHO("
			<?php include('resource/style/default.css'); ?>
		");

Open in new window

1
I have external css files and want to be able to modify some of the css from a php form ie: Set the font colour to #ffffff for example. When I input that into a text field, it updates the database but needs to update the css in the css file. There is too much css to inline into my view as that would have been an easy option. I am sure doing this must be pretty common but not sure what standard practice is for handling it?
0
How to export all my data in to a json array

Here is my code

<?php
ini_set('display_errors', TRUE);
error_reporting(E_ALL);


if(isset($_POST['submit']))
{


$UsrWorkOrder = $_POST['Work_Order'];


//db connect info
include 'conn.php';
//Where the query are stored 
include 'Query.php';




$result_Vis = odbc_exec($conn_Vis,$sql_Vis);  // Get Data From Result
    while($row2 = odbc_fetch_array($result_Vis))
    {
//Store the data in the new array

 

            $result_cor1db01_2 = odbc_exec($conn_cor1db01_2,$sql_cor1db01_2);  // Get Data From Result

            while($row3 = odbc_fetch_array($result_cor1db01_2))
            {







//This stores the data 
            	$Barcode = $row3["Work Order No"]."-". $row3["Serial No"];
       			$part = $row2["PART_X"];
        		$DESCR = $row2["DESCR_X"];
            	$Cable_Length = $row3["ValueInches"];
            	$MFG = $row3["Work Order No"]."-". $row3["Serial No"];
            	$Test_A = number_format($row3["Value1"],2);
            	$Test_B = number_format($row3["Value2"],2);



                    Echo "<br><br><img src=barcode.php?codetype=Code128B&size=80&text=".$row3["Work Order No"]."-". $row3["Serial No"] ." />";
                    Echo "<br>".$row3["Work Order No"]."-". $row3["Serial No"]."<br>";
                    Echo "Part Number: ".$part."<br>";
                    Echo "Description: " .$DESCR."<br>";
                    Echo "Mfg Lot Number: " .$row3["Work Order No"]."-". $row3["Serial 

Open in new window

0

PHP

120K

Solutions

33K

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.