PHP

119K

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

Whenever I make javascript changes people have to clear their cache etc. for the changes to properly take effect (most times for some people) . Is there a way I can perform a refresh on the web hosts side as I obviously can't email everyone telling them they need to clear their cache whenever I make a critical change.
0
Cloud Class® Course: Microsoft Office 2010
LVL 12
Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

After a transaction, data is sent to a view which contains the html email. In that view I have some info populated by session variables and some is just passed in an array from the controller to the view. The user receives the email and all the info displays but I have been told that if the email is forwarded, only the session variable data is in the body of the email but everything else is missing. I am not sure where to even start on this problem?
0
When I check on Checkbox then assign margin value which in Mysqli, should be added with amount
How to do?

checkbox.png
0
I have developed a website using php 7, jQuery and ajax. I have had a few people mention that the website does not work on Internet explorer. There has been no mention of what version but if they said Internet explorer then it sounds like prior to Edge. Apparently just a blank screen appears instead of the actual website. I am running a mac so don't have internet explorer to check myself. What would the best solution be? To either redirect them to a page that requests that they use a more modern browser or.... ?
0
Hello Experts!

Something is preventing checkbox and radio to display when this part of my Bootstrap is added. When I remove this part, those inputs show with default style.

Can you help me fix it?

See attached, please.
bootstrap_bug.txt
0
I need to display the attribute value on the checkout page for each product being purchased.  I am  using Woo Commerce 3.4.  Please give me the syntax to access the value.

Thanks,
0
Hello Experts!

How can I effectively display login error message in front of login button as text-danger?

My auth.php is currently echoing "Invalid Login" to a plain page (same script):
<?php

require '../includes/connection.php';

session_start();

// Do we have some POST data
if (!empty($_POST)):

    // Make sure we have some values
    $username = isset($_POST['username']) ? $_POST['username'] : null;
    $password = isset($_POST['password']) ? $_POST['password'] : null;

    // Run the query
    $select = $conn->prepare("SELECT ... ");

    $select->bind_param("s", $username);
    $select->execute();

    // Fetch a User
    $user = $select->get_result()->fetch_object();

    // Check that we found a user
    if ($user):

        // Check the password is correct
        if (password_verify($password, $user->Password)):

            // Update the login
            $login = $conn->prepare("UPDATE ... ");
            $login->bind_param("s", $username);
            $login->execute();

            // Set your session variable
            unset($user->Password); //we don't want the password stored in the session
            $_SESSION['user'] = $user;

            switch ($user->Role):

                case 'Admin':
                    header("location: ../admin/dashboard.php");
                    break;

                case 'Form Master':
                    header("location: ../form_masters/dashboard.php");
                    break;

                

Open in new window

0
Hello,
I have a php script which get images rows from database, and I want to display 3 images in a table row, and under each image 2 buttons.
Any idea on how can I do that?
Final output should be something like this
<table width=100% border=1>
<tr>
	<td> 
		<table width=100% border=1>
			<tr>image.jpg</tr>
			<tr>
				<td>Delete</td>
				<td>Edit</td>
			</tr>
		</table>
	</td> 
	<td> 
		<table width=100% border=1>
			<tr>image.jpg</tr>
			<tr>
				<td>Delete</td>
				<td>Edit</td>
			</tr>
		</table>
	</td> 
	<td> 
		<table width=100% border=1>
			<tr>image.jpg</tr>
			<tr>
				<td>Delete</td>
				<td>Edit</td>
			</tr>
		</table>
	</td> 
</tr>
<tr>
	<td> 
		<table width=100% border=1>
			<tr>image.jpg</tr>
			<tr>
				<td>Delete</td>
				<td>Edit</td>
			</tr>
		</table>
	</td> 
	<td> 
		<table width=100% border=1>
			<tr>image.jpg</tr>
			<tr>
				<td>Delete</td>
				<td>Edit</td>
			</tr>
		</table>
	</td> 
	<td> 
		<table width=100% border=1>
			<tr>image.jpg</tr>
			<tr>
				<td>Delete</td>
				<td>Edit</td>
			</tr>
		</table>
	</td> 
</tr>
</table

Open in new window

0
Because I am taking over for an ex-employee, I am tasked with finding out why a visitor who's logged in session times out 24 hours after inactivity can still see certain things that they should only be able to see when logged in, like special pricing. It was originally designed this way, because the boss wanted government customers who have logged in at some point to always be able to see their government pricing, whether they were currently logged in or not. Now, that decision has been reversed, and we only want them to see their government pricing if their current logged in session is valid.

we use Symfony2 on Unix / Apache if that matters

I have no idea if it's a cookie, a session, or whatever else

I know we utilize both but I don't know if the answer lies in either place
0
Hi Experts

Could you point how to populate Magento 1.9.x with data - insert table contents?

The database is correctly created but the tables are empty, making it dificult to start.

The data template that was given only reacreates the table structures without any data inside.

Thanks in advance.
0
Cloud Class® Course: Microsoft Azure 2017
LVL 12
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

I have the following json:
{
"count":2,
"page":1,
"pageSize":2,
"students":[{"forename":"Joe","surname":"Bloggs"},{"forename":"John","surname":"Doe"}],
"totalCount":2,
"totalPages":1
}

Open in new window


How can I alter this in PHP to just get the following:
{
[{"forename":"Joe","surname":"Bloggs"},{"forename":"John","surname":"Doe"}]
}

Open in new window


Thank you in advance
0
here is the arrays -

$reply = $stmt->all();
		$usList = array_unique($reply);

Open in new window


this is created from a table of regions.

what i am doing is taking all the time zone regions within the states to create a list of people from the different regions. now some people will be from the same region which makes duplications in the array. i need to only keep one per region so i tried using array)unique but it is removing fields which aren't dups.

dupe array contents -

Array(25)
0
:
{TIME_ZONE: "America/New_York"}
1
:
{TIME_ZONE: "America/New_York"}
2
:
{TIME_ZONE: "America/New_York"}
3
:
{TIME_ZONE: "America/New_York"}
4
:
{TIME_ZONE: "America/New_York"}
5
:
{TIME_ZONE: "America/New_York"}
6
:
{TIME_ZONE: "America/New_York"}
7
:
{TIME_ZONE: "America/New_York"}
8
:
{TIME_ZONE: "America/New_York"}
9
:
{TIME_ZONE: "America/New_York"}
10
:
{TIME_ZONE: "America/New_York"}
11
:
{TIME_ZONE: "America/New_York"}
12
:
{TIME_ZONE: "America/New_York"}
13
:
{TIME_ZONE: "America/New_York"}
14
:
{TIME_ZONE: "America/New_York"}
15
:
{TIME_ZONE: "America/New_York"}
16
:
{TIME_ZONE: "America/New_York"}
17
:
{TIME_ZONE: "America/New_York"}
18
:
{TIME_ZONE: "America/New_York"}
19
:
{TIME_ZONE: "America/New_York"}
20
:
{TIME_ZONE: "America/New_York"}
21
:
{TIME_ZONE: "America/New_York"}
22
:
{TIME_ZONE: "America/North_Dakota/Center"}
23
:
{TIME_ZONE: "America/Toronto"}
24
:
{TIME_ZONE: "America/Toronto"}

Open in new window



result after array_unique -

Array(1)
0
:
{TIME_ZONE: "America/New_York"}

Open in new window


as seen there is atleast two field on that array that should be in the sorted array. but they arent.
0
Hi Experts,

In WordPress, how do I create a  PHP template to be used by multiple of pages (not all)? I have already created my child theme.
0
from a whois on godaddy.com/whois
Name Server: NS75.DOMAINCONTROL.COM
Name Server: NS76.DOMAINCONTROL.COM
DNSSEC: unsigned

A website owner hires another person to blog his small business wordpress website
Website thinks his company is hosted elsewhere and thinks that his blogger has a dedicated server
I think it is hosted by godaddy
Maybe the godaddy nameservers point somewhere else

Is there another test I can show website owner where his website is hosted
I cant log into his godaddy or wordpress
0
Hi Experts

Could you point where a complete Magento 1.9.x could be downloaded?

It seens that the official site  no longer mantains that versions.

Thanks in advance
0
Hello Experts!

Please how can I store password as hashsed?

Here is the part of the script:
<?php

if ( ! empty($_POST) ){

    include('../includes/connection.php');

    ........

    // Let's insert the Data
    $users = $conn->prepare("INSERT INTO Users (Initials, Username, Password, Role, ClassAssigned) VALUES(?, ?, ?, ?, ?)");
    $users->bind_param("sssss", $_POST['initial'], $_POST['username'], $_POST['password'], $_POST['role'], $_POST["class_assigned"]);

    $userClasses = $conn->prepare("INSERT INTO UserClass (UserId, SubjectTaught, ClassTaught) VALUES (?, ?, ?)");
    $userClasses->bind_param("iss", $userId, $subject, $class);

    if ( $users->execute() ){

        $userId = $users->insert_id;

        foreach ($_POST['subject_taught'] as $key => $subject):
            $class = $_POST['class_taught'][$key];
            $userClasses->execute();
        endforeach;

        $response->message = "<strong>".$_POST["initial"]."</strong> successfully added.";
              $response->status = true;
              
    } else {
        $response->message = $conn->error;        
    }

    die( json_encode($response) );

}

?>

Open in new window

0
For the insert and update statements below, I need to check field canonical_url_id for an existing record value of 0 or empty... if it is, and if no other value has been entered, I need to replace the 0 or empty with NULL. How to, please?

              $existing = $db->runQuery("SELECT COUNT(*) AS cnt FROM dynamic_url WHERE qm_url_id = ".$qm_url_id);
              if($existing[0]['cnt'] == 0) {
              	  $db->runQuery("INSERT INTO dynamic_url (qm_url_id, title, meta_keywords, meta_description, heading, canonical_url_id)
              	  	             VALUES (".$qm_url_id.", '".addslashes($data['title'])."', '".addslashes($data['meta_keywords'])."', 
              	  	                     '".addslashes($data['meta_description'])."', '".addslashes($data['heading'])."', 
              	  	                     ".intval($data['canonical_url_id']).")", true);           
              } else {
              	  $db->runQuery("UPDATE dynamic_url SET title = '".addslashes($data['title'])."',
              	                                    meta_keywords = '".addslashes($data['meta_keywords'])."',
              	                                    meta_description = '".addslashes($data['meta_description'])."',
              	                                    heading = '".addslashes($data['heading'])."',
              	                                    canonical_url_id = ".intval($data['canonical_url_id'])."
              	                 WHERE qm_url_id = 

Open in new window

0
I am trying to force https with my .htaccess file but when I do, the layout breaks and I get 404 errors in console for pretty much everything from css files to js files etc. I am using a MVC structure.

In my config file I have:

define('URLROOT', 'https://mysite.com');

Open in new window


In my header all my css files are called like this:

<link href="<?php echo URLROOT; ?>/css/style.css" rel="stylesheet">

Open in new window


My .htaccess looks like:

<IfModule mod_rewrite.c>
 RewriteEngine on
 RewriteCond %{HTTPS} off
 RewriteRule ^(.*)$ https://mysite.com [L,R=301]
 RewriteRule ^$ public/ [L]
 RewriteRule (.*) public/$1 [L]
</IfModule>

Open in new window

0
Hello Experts!
Please how can I make this login script more secure? Help me use prepare statement and if possible use Ajax to validate at client side. Thank you so much.
<?php

require '../includes/connection.php';

session_start();
$timeout = 1440; // Set timeout period in seconds

if (isset($_SESSION['start_time'])) {
    $elapsed_time = time() - $_SESSION['start_time'];
    if ($elapsed_time > $timeout) {
        header("Location: ../logout.php");
    }
}
$_SESSION['start_time'] = time();

$date_time = date("Y-m-d H:i:s");

function clean($data) {
    $data = trim($data);
    $data = stripslashes($data);
    $data = htmlspecialchars($data);
    return $data;
}

//Login Query
if(isset($_POST['login_btn'])){

    $username = clean($_POST["username"]);
    $password = clean($_POST["password"]);
    
    $sql = "SELECT users.UserId AS UserId, users.Initials AS Initials, users.Username AS Username, users.Password AS Password, users.Role AS Role, users.ClassAssigned AS ClassAssigned, userclass.SubjectTaught AS SubjectTaught, tbl_subjects.Subject_Name AS Subject_Name, userclass.ClassTaught AS ClassTaught from ((users join userclass on((users.UserId = userclass.UserId))) left join tbl_subjects on((userclass.SubjectTaught = tbl_subjects.Subject_Code))) WHERE Username='$username'";
    $result = $conn->query($sql);

    if ($result->num_rows > 0) {

        // output data of each row
        while($row = $result->fetch_assoc()) {
            if($row['Password'] == $password 

Open in new window

0
Keep up with what's happening at Experts Exchange!
LVL 12
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.

Insert into pdo table not working and no error.

$stmt = new Database();
					//check to make sure there is a record to update 
				$query = "SELECT chk_name FROM a_test WHERE charityID = :clientID AND contactID = :contactId";
				$stmt->query( $query );
				$stmt->bind( ':clientID', $clientId);
				$stmt->bind( ':contactId', $contactId );
		     	$stmt->execute();
				$result = $stmt->all();

		if($result == null){
			foreach($_POST['chkStateCollection'] as $chkState) {
				$stmt = new Database();
					//Inserting check state.
				$query = "INSERT INTO a_test (charityID, contactID, chk_name) VALUES (:clientId, :contactId :chkName) ";
				$stmt->query( $query );
				$stmt->bind( ':clientId', $clientId );
				$stmt->bind( ':contactId', $contactId );
				$stmt->bind( ':chkName', $chkState );
		     	$stmt->execute();
				$result = $stmt->all();
			}
		} else {
				$testreply = "no rows detected";
		}

Open in new window


Ok so what this code is doing and suppose to do.  I am checking to see if a record exists first and this part works as expected if record exist goto else if not then create a record.

Now the record is created with two ID which is stored in a session they seem fine. now im not sure if the last one is the issue as i tried hard coding and same response but the field chk_name is populated by the forach which gets it details from ajax post array which looks like this -

(2) ["POSTITION", "FIRST_NAME"]

Open in new window


the problem is when it gets to the INSERT it doenst add and the ajax response is not successful with not errors. so im lost on what is the issue.
0
Hello,

I want to send a form with two actions. Those actions are to send two different values to another (the same) page. As individual actions these send but it's when I try to combine thw two actions into one form that I have problems.  

Something like this -

<form action="<?php echo 'addfav.php?id='. $teacher['id'] ;?>" 
<form action="<?php echo 'addfav.php?ids='. $_SESSION['session_ids'];?>"  method="post">

Open in new window


However,  from a bit of googling, I understand that a form can only send one action. From a bit of a reading online I made a number of failed attempts along these lines using input type 'hidden':

<form id="form" name="form" method="post" action="addfav.php">
<input type="button" class="btn btn-info btn-sm" />

<input type="hidden" name="teacherid" id="teacherid" value="<?php echo $teacher['id'] ;?>">
<input type="hidden" name="studentid" id="studentid" value="<?php echo $_SESSION['session_ids'];?> ">

</form>	

Open in new window



And then tried to pick up the posted values in addfav.php with the following

<?php if ((isset($_POST['teacherid']) && $_POST['teacherid'] != "") && (isset($_POST['studentid']) && $_POST['studentid'] != "")){

$studentid = $_POST['studentid']; 
$teacherid = $_POST['teacherid']; 

}	
?>

Open in new window



This doesn't work - Nothing happens when I press the button.

Is it correct that a form can't sent two actions, and if so, is using  input type 'hidden' the correct method moving forward? I'm trying to stick to using php and avoiding javascript if possible.  Any help, advice greatly appreciated as always.

Many thanks for reading.

Adam
0
so im displaying a array result of a drop down.

it returns this data here - this is what it looks like in a alert -

<select style ='width:100%;' class='formInput' name='property'2527'' id='property'2527''><option value=''>- select -</option>,<option value='test1' >test1</option>,<option value='test2' >test2</option>,<option value='test3' >test3</option>,</select>

Open in new window


this is how it looks in the console.log -

"<select style ='width:100%;' class='formInput' name='property'2527'' id='property'2527''><option value=''>- select -</option>"
1
:
"<option value='test1' >test1</option>"
2
:
"<option value='test2' >test2</option>"
3
:
"<option value='test3' >test3</option>"
4
:
"</select>"

Open in new window


So far so good to me it looks in correct order.

but when i append the coniner i get the following display

<select style="width:100%;" class="formInput" name="property" 2527''="" id="property"><option value="">- select -</option></select>
<option value="test1">test1</option>
<option value="test2">test2</option>
<option value="test3">test3</option>

Open in new window


as you can see this is a different format from the array the options are outside the select.

here is how the array is set-up -

if($cusData['propertyType'] >=4 && $cusData['propertyType'] <=6) {
							$teststring = ["<select style ='width:100%;' class='formInput' name='property'".$cusData['propertyId']."'' id='property'".$cusData['propertyId']."''><option value=''>- select -</option>"];
							$testResult = "property found";

								$stmt = new Database();

								$query = "SELECT *
											FROM custom_property_values
											WHERE property_id = :propertyID
											ORDER BY id ASC";
								$stmt->query( $query );
								$stmt->bind( ':propertyID', $cusData['propertyId'] );
								$stmt->execute();
								$result = $stmt->all();

								foreach($result as $selectData){
									array_push($teststring , "<option value='".$selectData['value']."' ".($subrow['infomation'] == $selectData['value'] ? "selected='selected'" : "").">".$selectData['value']."</option>");

								}//selectData
								
								array_push($teststring, "</select>");

Open in new window


any hints to what i am doing wrong ?
0
I'm using a wordpress theme and would like to move the site title line up on the line with the logo and menu. Is there an easy way to do this?
0
I need to add into the code below an IF statement (in the commented area), checking that the order number and a few other things are greater than 0... if they aren't, I need to return a message to the browser saying "no good" or whatever. If they are, then the code keeps going. The code below is tested and it worked, but now I just need that break in the middle that checks for data validation before inserting into the db and sending the email.
    public function indexAction()
    {

       $request_result = array('success' => false);
       if($this->get('security.context')->isGranted('ROLE_USER')) {
          $em = $this->getDoctrine()->getEntityManager();
          $dbAzure = new DbAzure();
          $user = $this->container->get('security.context')->getToken()->getUser();
          $request = $this->getRequest();
          
          $om_customer_id = $user->getCustomer()->getOmCustomerId();
          $order_number = $request->get('order_number');
          $qm_sku = intval($request->get('qm_sku'));
          $options = $request->get('options');
          $qty = intval($request->get('qty'));
          $email = $request->get('email');
          
          
          // Verify data is correct.. order_number > 0....om_customer_id > 0.. qm_sku > 0... qty > 0
          // if not value... don't write the info and return an error

          
          $request_result['success'] = $dbAzure->submitReturnRequest($order_number, $qm_sku, $options, $qty);
          
          

Open in new window

0
From some help here on EE I managed to get a 2 tier accordion working but now I need a third level. The problem is that every 2nd level has the same info for it's third level instead of the actual data associated with the second level.

		$this->db->query("SELECT `edition`, `serial`, `rep`, `prod_name`, `reg_price`, `sale_price`, `end_date`, `purchased`, `first_name`, `last_name`, `voucher_id`, `sp_name`
		FROM `vouchers` AS `v`
		INNER JOIN `bb_products` as `bbp` ON bbp.`prod_id` = v.`product_id`
		INNER JOIN `service_providers` AS `sp` ON sp.`service_provider_id` = v.`sp_id`
		LEFT JOIN `bb_users` as `bbu` ON bbu.`uid` = v.`customer_id`
		WHERE v.`rep` = :sp_id 
		GROUP BY `sp_name`, `prod_name`
		ORDER BY `sp_name`, `prod_name`");
		$this->db->bind(":sp_id", $_SESSION['sp_id']);
		$results = $this->db->resultSet();
		$groupedData = [];

    foreach ($results as $record):

        $key = $record->sp_name;
        $groupedData[$key]['header'] = $record;
		$groupedData[$key]['children'][] = $record;
		$groupedData[$key]['grandchildren'][] = $record;

    endforeach;

		return $groupedData;
		
		return $results;

Open in new window



<div class="container">
	<div class="panel-group" id="accordion">
		<?php foreach($data['voucher_history'] as $group): ?>
		<div class="panel panel-default">
			<div class="panel-heading">
				<h4 class="panel-title">
					<a class="collapsed" data-toggle="collapse" data-parent="#accordion" href="#<?php echo $group['header']->sp_name; ?>">
			

Open in new window

0

PHP

119K

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.