[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

Dear Experts,
how can I download mysql table as Excel using PHP page?
I want to download the table on the database as Excel not the existing PHP page...
thank you
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.

I have this code, provided by someone else:
<?php

$request = new HttpRequest();
$request->setUrl('https://api.ltl.xpo.com/rating/1.0/ratequotes');
$request->setMethod(HTTP_METH_POST);

$request->setQueryData(array(
  'format' => 'XML'
));

$request->setHeaders(array(
  'cache-control' => 'no-cache',
  'content-type' => 'application/xml',
  'authorization' => 'Bearer 5ce5e6e3304fd4e069b1c00f1c1f9bab'
));

$request->setBody('<?xml version="1.0" encoding="UTF-8"?>
<GetXpoLtlRateQuoteRqst xmlns="http://www.ltl.xpo.com/API/LTLRatingAPI">
<shipmentInfo>
    <paymentTermCd>P</paymentTermCd>
    <accessorials>
        <accessorialCd>DNC</accessorialCd>
        <accessorialCd>GUR</accessorialCd>
    </accessorials>
    <commodity>
        <grossWeight>
            <weight>500</weight>
            <weightUom>lbs</weightUom>
        </grossWeight>
        <nmfcClass>100</nmfcClass>
        <hazmatInd>false</hazmatInd>
    </commodity>
    <shipmentDate>2018-11-19</shipmentDate>
    <shipper>
        <address>
	<acctInstId>117258878</acctInstId>
            <postalCd>93727</postalCd>
        </address>
    </shipper>
    <consignee>
        <address>
            <postalCd>92027</postalCd>
        </address>
    </consignee>
</shipmentInfo>
</GetXpoLtlRateQuoteRqst>
');

try {
  $response = $request->send();

  echo $response->getBody();
} catch (HttpException $ex) {
  echo $ex;
}

Open in new window


It fails with: Fatal error: Class 'HttpRequest' not found in /home/lakoshva/public_html/freight_test.php on line 3

Doesn't there have to be something like "require once xxxxxxxxxxxxxclass.php"?

Thanks
0
Hi,I'm having trouble trying to change the bootstrap .active class state via jquery.I've googled and found several solutions but none of them are working for me.Here is my html code:

[code]<section id="hero">
   			<div class="container-fluid">
               <div class="container">
				   <div class="row">
						<div class="col-md-12">
							<nav class="navbar navbar-toggleable-md navbar-light">
							  <button class="navbar-toggler navbar-toggler-right" type="button" data-toggle="collapse" data-target="#navbarNavDropdown2" aria-controls="navbarNavDropdown2" aria-expanded="false" aria-label="Toggle navigation">
								  <span class="navbar-toggler-icon"></span>
								  <span class="fas fa-times hide" data-wow-delay="2s"></span>
							  </button>
							  <a class="navbar-brand logo" href="index.php"></a>
							  <div class="collapse navbar-collapse" id="navbarNavDropdown2">
								<ul class="navbar-nav ml-auto">
								  <li class="nav-item active">
									<a class="nav-link" href="index.php">Home <span class="sr-only">(current)</span></a>
								  </li>
								  <li class="nav-item">
									<a class="nav-link" href="about.php">About Us</a>
								  </li>
								  <li class="nav-item">
									<a class="nav-link" href="howitworks.php">How it Works</a>
								  </li>
								  <?php
								  if( $_SESSION['loggedInUser'] ) { // if user is logged in
								  ?>
							      <li class="nav-item dropdown">
									<a class="nav-link" 

Open in new window

1
I am not sure if this join is going to be possible but I am asking here in the hope that it will be.

I have an order_detail table:

order_id
product_id
product_qty
product_price

So, some data might look like

1      25      2      299
2      26      1      199

And a coupon table (I have left out the other fields that aren't necessary for this question)

voucher_id
product_id
rep
purchased
order_id

And some data:

#12675      25      14      2018-11-05      1
#12676      25      14      2018-11-05      1
#12677      26      12      2018-11-07      2

I want to show a report of each voucher/coupon sale without duplicating data. My current query ends up showing the same coupon number twice.


 
      $this->db->query("SELECT `serial`, `rep`, `purchased` FROM `vouchers` AS `v`
        INNER JOIN `order_detail` AS `od` ON od.`order_id` = v.`order_id`
        WHERE cast(`purchased` as date) BETWEEN :first_day AND :last_day
        ");
        
        $this->db->bind(":first_day", $first_day);
        $this->db->bind(":last_day", $last_day);
        $results = $this->db->arraySet();
        return $results;

Open in new window

1
Hi,
I'd like to print each one of these tickets on a envelope (#10), so I would like to output a single pdf document with 4 pages, one ticket per page. I don't know if it's possible to print my HTML content on an envelope sized 9.5" x 4.125". If you look at the screenshot attached, you'll see I have all 4 tickets on a single page. I want to create a single PDF document with multiple pages, again one ticket per page.
Here is my code I have so far:
// winning tickets pdf
function fetch_data() {  
      $output = '';
      $userID = ($_SESSION["loggedInUserID"]);
      //$conn = mysqli_connect("localhost", "lormar5_wo693", "sDieYQb752KZc!;", "lormar5_wo693");  connection to theme
      $conn = mysqli_connect("localhost", "root", "root", "db_hockeypoolfundraiser");
	  $sql = "SELECT * FROM participants LIMIT 1";  
      $result = mysqli_query($conn, $sql);  
      while($row = mysqli_fetch_array($result))  
      {       
      $output .= '<tr>
	  			<td style="border-bottom: 1px solid #dfdfe0;">
				<br><br><strong>Winners Name:</strong> '.$_SESSION["participantName"].'
				<br><br><strong>First Goal Time:</strong> '.$_SESSION["firstGoalTime"].'
				<br><br><strong>Game Date:</strong> '.$_SESSION["gameDate"].' <br><br>
				</td>
				
				<td style="border-bottom: 1px solid #dfdfe0;">
				<br><br><strong>Phone:</strong> '.$_SESSION["participantPhone"].'
				<br><br><strong>Amount:</strong> $'.$_SESSION["priceFirstGoal"].'
				<br><br><strong>Player:</strong> 

Open in new window

0
Anyone know why the input "ScreenWidth" has a value of nothing instead of 1920?  I have tried " as well as '.
Where's the value?
1
Dear all,

I would like to hear from you some ideas on how make "Deep Document Summarization: Combining Text and Images" besides extracting paragraphs. And if PHP it is an appropriate language for doing this task

I am looking for ideas and suggestions

Sincerely
0
I have a form/page that I'm using to book in stock based on a poNumber that generates the stock items linked to that poNumber/supplier. Currently for each line (there may be 10 items for example on order) the user needs to add qty rec'd, qty outstanding, receipted by and delivery note number in the form for each line.

I want to short cut some of the data entry by having a single entry for receipted by and delivery note number but for this to populate the rows for each entry once submitted.

The code I have at the moment is as follows: -

<div class="container">	
	<form class="form" method="post" action="transit_temp.php">	
	
	<?php
	
	$poNumber = isset($_POST['poNumber']) ? $_POST['poNumber'] : false;
	
	$poNumber = $mysqli->real_escape_string($poNumber);
	
	$index=0;

	$query = 'SELECT * FROM goodsInTrans WHERE poNumber = "'.$poNumber.'"';
			
				if (!$result = $mysqli->query($query)) {
				$err
				= "QUERY FAIL: "
				. $query
				. ' ERRNO: '
				. $mysqli->errno
				. ' ERROR: '
				. $mysqli->error
				;
				trigger_error($err, E_USER_ERROR);
				}		
	
				while ($row = $result->fetch_object())
				
				{ 

				?>
					<div class="form-group row">
						<div class=""><input type="hidden" 				class="form-control" 	name="data[<?php echo $index; ?>][supplier]" 			value="<?php echo $row->supplier ?>"/></div>
						<div class="col-xs-3"><input type="text" 		class="form-control" 	name="data[<?php echo $index; ?>][sku]"	 				value="<?php echo $row->sku 

Open in new window

0
I have a column with the following structure:
id categories title    categoryid
1	A|B|	   First	100		
2	A|B|	  second	100		
3	A|B|	   third	100		
4	A|B|	   fourth	100		
5	A|B|	   Five     100

Open in new window


I need a php code snippet which check whether all values of  categories columnn for categoryid=100 are identical or not. If all identical then print message "Same values" otherwise "Not same"
1
I need to search for an order in my WooCommerce back office by email address.  I can see the email address in wp_users but don't know how to put a name to the email address.  Is there a plugin or mysql code that will accomplish that?

Thanks,
0
Bootstrap 4: Exploring New Features
LVL 12
Bootstrap 4: Exploring New Features

Learn how to use and navigate the new features included in Bootstrap 4, the most popular HTML, CSS, and JavaScript framework for developing responsive, mobile-first websites.

  <?php if ( ! isset($_GET["company"]) ): ?>

            <p>No Company Info has been passed in!</p>

        <?php else: ?>

            <?php
            // Let's run the query
            $query = $conn->prepare("SELECT frm_id, frm_companyname, frm_contact, frm_email, frm_rep, frm_date, frm_return, frm_timefrom, frm_timeto, frm_comment1, frm_comment2, frm_comment3, frm_comment4, frm_comment5, frm_todo1, frm_todo2,  frm_todo3,  frm_todo4,  frm_todo5, frm_updated  FROM siteform WHERE frm_companyname = ?");
            $query->bind_param("s", $_GET['company']);
            $query->execute();
            $results = $query->get_result();
            ?>
     
            <?php while ($row = $results->fetch_assoc()):$style = "";
  //if ($row['frm_id'] < "5"){
    //$style2 = "style='background:#FF0000;'";
  //} 
                  
  //if ($row['frm_id'] > "5"){
    //$style2 = "style='background:#FFF000;'";
  //} 
         //if ($row['frm_id'] =="5"){
    //$style2 = "style='background:#ddd000;'";
  //} 
       $data_db = $row['frm_date'];
       $current_date = date('Y-m-d', strtotime(" Today"));
        $current_date2 = date('Y-m-d', strtotime(" -1 month"));
        $current_date3 = date('Y-m-d', strtotime(" -2 month"));
        $current_date4 = date('Y-m-d', strtotime(" +1 day"));
        $current_date5 = date('Y-m-d', strtotime(" +1 month"));
         $current_date6 = date('Y-m-d', strtotime(" +2 month"));
    
if ($data_db == $current_date){
    $style = 

Open in new window

0
I'm building a Shopping Cart for a client and I'm at that point where the order has been tallied with taxes and shipping. I've got a total, I've got the client's email address and I'm ready to forward this all to Paypal but I'm stuck.

First off, the buttons that you can create from Paypal's free interface seem to limit your dollar amount to something that's fixed. That's not going to work because the total amount being charged in the Cart is going to vary based on what the customer has ordered.

Secondly, the "success" page, for my design, has to have the session variable embedded within the URL. That's how I'm documenting the fact that the order has been successfully paid for.

And finally, I want the screen that the customer gets to have the name of my client's business. Right now, they're getting this:

paypal screen
That's more aesthetic than it is anything else, but I've worked some with Paypal's dev tools and it seems like that's a possibility.

This is where I'm at right now...

<form action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_top">
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="encrypted" value="-encrypted code from Paypal's tools that represent a button created as part of my client's account. ">
<input type="hidden" name="amount_x" value="1.00"> <!-- my attempt to dictate the dollar amount being charged. It's not working -->
<input type="hidden" name="return" 

Open in new window

0
Hello,
I'm working on a code that can record vocal messages and store them into a database to retrieve them later on, but my PHP script isnt working and I don't have enough expertise in web dev to correct it, can someone help me please ?
index.html
upload.php
app.js
0
Dear All,

I have a device (installed on vehicle) which sends latitude and longitude on the Server through GPS. I have a route of that vehicle which is successfully plotted on Google Map.

My Problem is how can I plot latitude and longitude at runtime on Google Map in PHP dynamically on Desktop Application. I want to plot fetched latest latitude and longitude on Google Map to show where the vehicle is running.
0
This is a php script, which basically does the send mail function via terminal shell, I am studying it and the curious thing is that it worked in my tests only in the Ubuntu 14.04 versions with php5 and postfix. But I could not get it to work on Ubuntu 18.04 or Debian 9. I would like to ask for help to change the code in order to make it work in those versions. Thank you.

javali.php
1
I need these to come in one email not three separate ones.  How can I combine these?
$sent = mail( "$webmaster_email", "Subscriber Alert", "From: $email_address");
$sent = mail( "$webmaster_email", "Subscriber Alert", "Name: $name");
$sent = mail( "$webmaster_email", "Subscriber Alert", "Code: $postal_code");

Open in new window

1
I have some code which stores session detail in a database, but when I issue the command 'session_regenerate_id();' I get
PHP Catchable fatal error:  session_regenerate_id(): Failed to create(read) session ID

<?php
    //Session
    class pdoSession {
        //DB Object
        private $db;

        public function __construct($pdoDB){
            // Instantiate new Database object
            $this->db = $pdoDB;

            // Set handler to overide SESSION
            session_set_save_handler(
                array($this, "_open"),
                array($this, "_close"),
                array($this, "_read"),
                array($this, "_write"),
                array($this, "_destroy"),
                array($this, "_gc")
            );

            // Start the session
            session_start();
        }

        //Open
        public function _open(){
            // If successful
            if($this->db){
                return true;
            }
            // Return False
            return false;
        }

        //Close
        public function _close(){
            // Close Session
            return true;
        }

        //Read
        public function _read($id){
            $stSession = $this->db->prepare("SELECT `data` FROM `sessions` WHERE `SID` = :id");
            $stSession->bindValue(':id', $id, PDO::PARAM_STR);

            if($stSession->execute()){
                $row = $stSession->fetch(PDO::FETCH_ASSOC);
          

Open in new window

0
I need a great WebHost for a site that will be using PHP and MySQL for a small project.  The site will be having users sign in, submit and edit forms.  They want to keep the history online, with frequent backups and good security.  

What a good company for professional hosting?


Thanks.
0
Hello all,

I have a line in my code which checks to see if the email value entered in a submitted form already exists in the database. If so,  a value of 0 or 1 is assigned to a string and the string value is displayed.

$select = mysqli_query($db_connection, "SELECT `email` FROM `teachers_table` WHERE `email` = '".$_POST['email']."'") or exit(mysqli_error($db_connection));
	if(mysqli_num_rows($select)) {
    $email_exists = '1';
	}  
	else{
		$email_exists = '0';
	}
		echo $email_exists;

Open in new window


This part seems to work as intended - at least the value of 0 or 1 is displayed correctly depending on whether the email exists in the database or not. The next part of my code calls another function, (which in turn calls another validation function) which displays errors.

The validation worked but I added to it:
	if($email_exists == '1') {
      $errors[] = "EMAIL Exists IN OUR DATABASE";
    }

Open in new window


However, when I do this, I get an  Undefined variable: email_exists in... notice / error.

I don't understand why this is coming up as not defined if the function is being called after I have defined this value.  The error message is displayed even though I can see the value of $email_exists (i.e. the 1 or 0) output in the screen.

I've tried removing the quotes, changing to single quotes and using TRUE and FALSE but this didn't appear to change anything.

 When I use '=' instead of '==' i.e:
if($email_exists = '1') {
      $errors[] = "EMAIL Exists IN OUR DATABASE";
    }

Open in new window


...the not defined error goes away but the logic doesn't work, in that $email_exists seems to be always 1 and the error EMAIL Exists IN OUR DATABASE is always displayed.

Any help, as always, much appreciated.

Many thanks,

Adam,
0
CompTIA Cloud+
LVL 12
CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

Hi everyone,

I am learning and I want to make search with more filters. I have one table where I have three columns with foreign keys which are related to other tables. So, I have 4 tables. First table containt user details, second table contain category, third table contain institution, and fourth table containt city.

First table look like on picture below named (users)



Second table (named categories)



Third table (named institutions)



Fourth table (named city)



I have this HTML form:
<form action="izvjesce.php" method="GET">
										<div class="form-group col-lg-6">
										<select  class="form-control" name="status" required>
											<option  value="Aktivan" checked><b>Aktivan</b></option>
											<option  value="Neaktivan"><b>Neaktivan</b></option>
										</select>
										</div>
										<div class="form-group col-lg-6">
										<select  class="form-control" name="spol">
											<option  value=""><b>Spol</b></option>
											<option  value="Muški"><b>Muški</b></option>
											<option  value="Ženski"><b>Ženski</b></option>
										</select>
										</div>
										<div class="form-group col-lg-6">
										<select  class="form-control" name="pos_mj" >
											<option  value="">Izaberi mjesec</option>
											<option  value="siječanj">Januar/Siječanj</option>
											<option  

Open in new window

1
Hi

I'm not a big fan of Googles reCAPTCHA  having clicked on 100's images of traffic lights, bicycles  and fire hydrants to be asked please try again

However can someone explain how  to validate it prior to submitting a form?

I'm assuming this is done within a JavaScript onSubmit function ??

I'm also assuming Is there no PHP  validation as reCAPTCHA  is a JavaScript library so if   isn't enabled reCAPTCHA   wont work


The code bellow is just to get going
<?php
error_reporting(E_ALL); 
$submit = filter_input(INPUT_POST, "submit");
if($submit){
  // validate form 
  $html = "<div>Hello Thank you for your message</div>";
  }
 
?>

<!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<html>
  <head>
    <meta charset="UTF-8">
    <title>Send a Message</title>
    <script src='https://www.google.com/recaptcha/api.js'></script>
      <script>
    function onSubmit() {
      document.getElementById("MyForm").submit();
    }
  </script>
  </head>
  <body>
    <?php
    if ($html){
    echo $html;
      }
    else
      {
      
      
    ?>
    <div class="FormWrap">

          
  <fieldset>

          
    <legend>Email Form</legend> 

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

          
      <p><label for="Fname">Enter full name</label><input type="text" 

Open in new window

0
my view is not passing data to the controller. and i am new to codeigniter and i am confused..anyone please help

this is my view
<?php require_once(APPPATH.'views/web/header.php');?>
<?php

$ses=$this->session->userdata('webuser');
/*print_r($ses);
die;*/


?>
<style>
.select2-container {
width : auto !important;
}
.select2
{
width : 100% !important;
}
.select2-container--bootstrap
{
width : auto !important;
}
.numcolor{
color:black;
}
.backcolor{
background:#32c5d2!important;
}
.activecolor{
font-weight:bold;
}
.nav-pills>li.active>a, .nav-pills>li.active>a:focus, .nav-pills>li.active>a:hover{
	background:grey!important;
}

<?php if(strtolower($this->uri->segment(3))=="parentuser"){?>
.one{
background:#32c5d2!important;

}	
.onenumcolor{
color:black;
font-weight:bold;
}

.twonumcolor,.threenumcolor,.fournumcolor{
color:#32c5d2!important;
}
.two>a:hover{
background:black!important;

}
.three>a:hover{
background:black!important;

}
.four>a:hover{
background:black!important;


}
<?php }elseif(strtolower($this->uri->segment(3))=="student"){?>
.one,.two{
background:#32c5d2!important;
color:white;
}
.twonumcolor{
color:black;
font-weight:bold;
}
.onenumcolor{
color:white!important;

}
.threenumcolor,.fournumcolor{
color:#32c5d2!important;
}
.one>a:hover{
background:black!important;

}
.three>a:hover{
background:black!important;

}
.four>a:hover{
background:black!important;


}
<?php	}?>
				

				
</style>

<div class="page-content-wrapper">
	<!-- BEGIN CONTENT BODY -->

Open in new window

0
HI,

I am working on a project where I get an error I don't understand.
The error is this:
Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in /var/www/kroweb.dk/public_html/ourdev/demo/classes/Post.php on line 42
and I put in the Post.php file here below.
You can see the page here: https://kroweb.dk/ourdev/demo/index.php

I hope that somebody can help me to fix this :)

	
<?php
  class Post { //ændret fra class User
    private $user_obj; //ændret fra class User
    private $con;

    public function __construct($con, $user) {
      $this->con = $con;
      $this->user_obj = new User($con, $user); //ændret fra class User
    }

    public function submitPost($body, $user_to) { //ændret fra class User - ALT HERFRA OG NED
      $body = strip_tags($body); // fjerner HTML tags
      $body = mysqli_real_escape_string($this->con, $body); //fjerner enkelt '' fra $body, således at det ikke skaber problemer i en sql query
      $check_empty = preg_replace('/\s+/', '', $body); //Fjerner alle mellemrum i $body (fordi man ikke skal kunne lave en post med mellemrum alene)

        if($check_empty != "") { //hvis der er indhold i $check_empty - som er er $body uden mellemrum

          $date_added = date("Y-m-d H:i:s"); //aktuel dato og tid variabel
          $added_by = $this->user_obj->getUsername(); // brugernavn variabel
            if($user_to == $added_by) {
              $user_to = "none"; //hvis der laves en post fra egen 

Open in new window

0
I'm fairly novice with PHP, but I can usually figure things out. But I'm stuck on working around this legacy code that we use on our sales form.
 I have to shoehorn in another Card processing merchant that does things a little differently with their API.

This is processing the response from a cURL API where I receive a SOAP XML response. I'm having some issues with the actual response as well, so I have it sampled in what appears to be a proper xml format, then attempting to parse out the message objects.

The process:
1. I have the response XML converting into a "SimpleXMLElement" with the simplexml_load_string
2. Then the XML is "converted to an array", I think, with the $array = (array)$xml;
3. Then, the code should be able to look into the array values and process a Success or Failed based on the Status Value
4. Then the $data is json encoded and is passed to the JavaScript file for further processing of the notification and filling in the Auth code field of the sales form.

The Problem(s):
1. You'll see in the PHP code that I have 2 testing sections to process the response. The first uses the $array and the second skips the array and just uses the $xml. One is commented out for testing the other, of course.
2. When using the $xml section to get the values, I get real close to what I need until it get json encoded, then the output just says Object Object in the JS Alert. It appears that the code is finding the proper value of the key, but it's not …
0
Hi,
I have a Table called game with 4 columns:
clock_first_goal, clock_last_goal, clock_first_penalty, clock_last_penalty

and a second Table called tickets_one with 5 columns:
clock_one, clock_two, clock_three, clock_four, clock_five
where I've imported random clock times between 0 and 20:00 minutes that of a NHL period.
There are 1200 total times (60 seconds x 20 minutes) in 5 columns so there are 240 records in this Table.

In my application I have a page called enter_games.php. What I want is when the admin submits the times for First Goal, Last Goal, First Penalty and Last Penalty, I want to check if any of these values match the values in the tickets_one Table. If they do I just want to echo "we have a match!", if not I want to echo "no match".

I'm not sure the best way to do this if it should be a Join, if statement or loop etc... I think it can be done with an if statement.
I'm somewhat new to php and mysql. This is the section of the code I'm trying to get to work:

// find matching results
// query the database with client ID
$query = "SELECT * FROM tickets_one";
$result = mysqli_query( $conn, $query );

// if result is returned
if( mysqli_num_rows($result) > 0 ) {

    // we have data!
    // set some variables
    while( $row = mysqli_fetch_assoc($result) ) {
        $time1    = $row['time_one'];
        $time2    = $row['time_two'];
        $time3    = $row['time_three'];
        $time4    = $row['time_four'];
        $time5    = 

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.