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

i created one html5 form which is connected to phpmyadmin .The form is opening in other PC's with the help of my IP address.But why my form is not opening in other places when i'm using with ip adderss???
0
Online Training Solution
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Basically i want to store and be able to download word, excel pdf et.. file in mysql database. i have succeeded in storing the files but the download aspect is giving me hell. i wrote the script to down the files, but every time the downloaded files gets damage or corrupt. This is the error when i attempt to open the downloaded microsoft office document: we are sorry we can not open the file because we found problem with it content. this file is corrupt and can not be open.


please help, i have been on this for days.

this is my downlo.php file

if(isset($_GET["dow"])){
      ob_start();
      $path = $_GET['dow'];
      $mysqli = new mysqli("localhost","root","","extenderaid");
if($mysqli-> connect_error)
      die("database connection fail".$mysql->connect_error);

$qry = mysqli_query( $mysqli,"select doc from document where doc= '$path'");
header('Connection: Keep-Alive');
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="'.basename($path).'"');
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('Content-Length: ' . filesize($path));
ob_clean();
readfile($path);

}




this is my upload file
include('section.php');
  
 $fload_error='';
  $discription_error='';
$discr='';
$submis_error='';
$submis='';
$ngo_error='';
$success='';
$target_file 

Open in new window

0
So on this page I have the ability to clone multiple inputs depending on how many flights a user has:

http://groupplanner.gallitin.com/flight/create?tripID=22&tripName=ABC&depart=07%2F20%2F2017&return=08%2F05%2F2017

When I try to submit that of course it bombs as originally it was not an array and only allowed a single input.

Current code:
public function store(Request $request){

        $flight = new Flight;
        $flight->airline = request('airline');
        $flight->flightNumber = request('flightNumber');
        $flight->departing = date('Y-m-d H:i:s', strtotime(request('departing')));
        $flight->seatNumber = request('seatNumber');
        $flight->tripID = request('tripID');
        $flight->userID = Auth::id();
        $flight->save();
        $tripID = request('tripID');
        $tripName = request('tripName');

        return redirect()->route('flight', ['tripID' => $tripID,'tripName' => $tripName]);

    }

Open in new window


How can I modify this since I now have the data coming across as an array?  Is it just a normal foreach loop like I would do in PHP or is there a better/easier method to do with Laravel and Eloquent?
0
I had this question after viewing SQL How do I INSERT INTO two tables at once and pass the ID from the first to the second.
Dealing with two tables: product and product_volume.
I have a dynamic form, how do i insert into the product table and use the ID created to populate product_volume in one query (in a php function). I need to create multiple rows for 1 product ID which will have different volumes and prices.
0
I want to check for the presence of a substring within a string using a PHP variable. Something like this:

<?php 

$something="A string that contains the word script";

?>

<!DOCTYPE html>
<html lang="en">
<head>
<title>JQuery Text Exchange</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
</head>

<body>

<script>

var testStr = <?php echo $something;?>

if ($(testStr:contains("check")).length > 0)
{
	 alert("String Found");
}
	

</script>
</body>
</html>

Open in new window


So, tell me if the word "check" shows up in the PHP variable $something. How can I do this?
0
So I've got a function in PHP. If no records are found as a result of a SELECT statement, then right now, the syntax I'm working on has this:

echo "We were unable to match the info you provided.";

I want to instead, load some text via JQuery into a div. Right now, I've got this:

echo "<script>$('#header_text').html('We were unable to match the information you provided.\n Please try again.');</script>";

It's not working. I think I know why in that what I've got currently is something that's put in motion by an action of some kind. A click, a button - something. Without that "event," I don't have anything.

Let me know if that's accurate and, if you would, also tell me how I can use JQuery to load some new text into the <div> rather than simply echoing a message.

Thanks!
0
I know how I can get the data needed, but want to follow Laravel/MVC practices here and new to it.

I have a page that stores data that a user sends through a form.  Once they submit they are redirected to a new page that I'd like to display some of the data back to them.

For example, currently any data I want to display I'm just passing in the URL.
$trip = new Trip;
        $trip->tripName = request('tripName');
        $trip->departing = date('Y-m-d H:i:s', strtotime(request('departing')));
        $trip->returning = date('Y-m-d H:i:s', strtotime(request('returning')));
        $trip->save();
        $tripID = $trip->id;
        $tripName = request('tripName');

        return redirect()->route('flight', ['tripID' => $tripID,'tripName' => $tripName]);

Open in new window


Then within the view I just:
{{ $_GET['tripName'] }}

Open in new window


Is that how I should be doing it?  Or when they hit the new view is there an easy way to grab that data with a DB call?  If so should this be done in the view or do I need to serve somehow from the controller?

Thanks
0
Here's what the programmer prior to me has in place:

$out .= <<<OUT
                              <script>
                              var text=$('#header_text').text();
                              $('#header_text').text('Click on the "Yes" button if the name listed below is you. Otherwise, click "No."');            
                              
                              $('#verifyUseryes').click(function(){
                                    window.location='$portalLink';
                              });
                              $('#verifyUserno').click(function(){
                                    $('#header_text').text('Please enter your personal information and click on "submit!"');            
                                    $('#step_1').show();
                                    $('#window').html('');
                              });
                              </script>
OUT;

They used HEREDOC, which is fine, but the challenge I'm running into is that when I try to do this:

$('#header_text').text('Click on the "Yes" button if the name listed below is you.\nOtherwise, click "No."');

or this...

$('#header_text').text('Click on the "Yes" button if the name listed below is you. <br>Otherwise, click "No."');

I get the actual characters ("\n" or "<br>") rather than the actual line break.

I want to maintain the HEREDOC dynamic, at least for now. Any suggestions on how to get that line break happening?
0
I would like to make a parse of postfix mail log in an HTML/PHP page with a search bar and then creating a dynamic table with all these tags. when the table is done I should be able to click on the "Date" and another page should open with others info about that log *(2)

I will copy an example of a log

search: from: ...... to: ...... date: from: .... to: ....

Eg Table example: Date | time | from: Jack | to: John | status:

*(2)

client:
message
id:
Size:
relay:
delay(s)
status detail
KLMS:
av-reason:
ap-reason:
as-reason:
cf-reason:
action:
rules:



809318:Jul 11 14:13:50 amail-2014 postfix/smtpd[17127]: 78F5E83F28: client=mx0a-00164e02.pphosted.com[67.231.149.89]
809320:Jul 11 14:13:50 amail-2014 postfix/cleanup[18135]: 78F5E83F28: message-id=<ADR420000021230890209457A56BCF141EE799C64C575B380E1C@molex.com>
809324:Jul 11 14:13:50 amail-2014 postfix/qmgr[27711]: 78F5E83F28: from=<NO-REPLY@MOLEX.COM>, size=30390, nrcpt=1 (queue active)
809325:Jul 11 14:13:50 amail-2014 postfix/smtp[11782]: 78F5E83F28: to=<*****@SYLEX.SK>, relay=mail1.sylex.sk[195.168.126.227]:25, delay=0.73, delays=0.59/0/0.01/0.13, dsn=2.6.0, status=sent (250 2.6.0 <ADR420000021230890209457A56BCF141EE799C64C575B380E1C@molex.com> [InternalId=50607599648815, Hostname=SYXEX01.sylex.sk] Queued mail for delivery)
809326:Jul 11 14:13:50 amail-2014 postfix/qmgr[27711]: 78F5E83F28: removed
809323:Jul 11 14:13:50 amail-2014 KLMS: not processed: …
0
Dear Experts,
When I visit a web site, the home page is asking a question like :

http://www.trt.tv wants to Show notifications

How can I see the notifications?

how can the web site push the notifications? How can the users see the notifications?

How can I do the same on my web site?

I use PHP
0
Independent Software Vendors: We Want Your Opinion
Independent Software Vendors: 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!

I need to palace DOB in text format only so i wrote the code like this but i need some validation like DD should be upto 31 days only,MM should be upto 12 months and similarlu YYYY also
  DOB<input  pattern="^([0-9]{02}/[0-9]{02}/[0-9]{4})" type="text" placeholder="DD/MM/YYYY"></td>

Open in new window

0
If one EmployeeID is already exists in the phpmyadmin another employee should not enter the data with the same EmployeeID so can any one add alert message to my code???
<?php

$EmployeeID = "";
if(isset($_POST['EmployeeID'])){
    $EmployeeID = $_POST['EmployeeID'];
} 

$FirstName = "";
if(isset($_POST['FirstName'])){
    $FirstName = $_POST['FirstName'];
 } 

$MiddleName = "";
if(isset($_POST['MiddleName'])){
    $MiddleName = $_POST['MiddleName'];
 } 
                                                                                                                                                                                                                                                                                                                                                                                            
$LastName = "";
if(isset($_POST['LastName'])){
    $LastName = $_POST['LastName'];
 } 

$FatherName = "";
if(isset($_POST['FatherName'])){
    $FatherName = $_POST['FatherName'];
 } 

$SpouseName = "";
if(isset($_POST['SpouseName'])){
    $SpouseName = $_POST['SpouseName'];
 } 

$MotherName = "";
if(isset($_POST['MotherName'])){
    $MotherName = $_POST['MotherName'];
 } 

$DOBDay = "";
if(isset($_POST['DOBDay'])){
    $DOBDay = $_POST['DOBDay'];
 } 

 $DOBMonth = "";
if(isset($_POST['DOBMonth'])){
    $DOBMonth = $_POST['DOBMonth'];
 }

$DOBYear = "";
if(isset($_POST['DOBYear'])){
    $DOBYear = $_POST['DOBYear'];
 } 

$DateofBirth 

Open in new window

0
See my php code below. You will see the two functions are virtually the same, but select different field names. I have a few more functions to add that are similar too. Instead of duplicating the code each time can I create a foreach loop to dynamically create each function? i.e. A variable of the function name and field names? If so can you please show me an example using my code?

public static function find_all_media_type_compats() {
		return self::find_by_sql("SELECT DISTINCT media_type_compat FROM ".self::$table_name." WHERE type = 'Media' AND media_type_compat != '' ORDER BY media_type_compat ASC");
  }
	
  public static function find_all_media_applications() {
		return self::find_by_sql("SELECT DISTINCT media_applications FROM ".self::$table_name." WHERE type = 'Media' AND media_applications != '' ORDER BY media_applications ASC");
  }

Open in new window

0
Hello Everyone,
I have one issue about PDF file.
I generate dynamic PDF template(Like Certificate). The file content some fields like Firstname,Lastname,Course type,etc.
I want to write dynamic content into PDF as firstname, lastname etc.

I have tried MPDF,FPDF etc tools but that's not working.Also used PDF to html conversation but after converting HTML regenerates not possible from html into proper format.

Please let me know if anyone have other idea to direct replace content into Existing pdf using PHP.
I have sample pdf files.
I want to replace content into given attachment.
This is demo file i have many files with different templates.
Waiting for help.
Certi-FWT-basis-en-opfris_PDF.pdf
0
please look attached file.i need to print the data individulaly
i created two tabular forms in phpmyadmin those two are linked data is fetching here the problem is while fetching the data i'm getting the employess data continusly.
for example : i created two tables one is employee family and other one is employee personal.while fetching the data all employees family details are fetching at a time similarly personal details comming like that but i want in order
<h3 style="font-size:10%;"><h3 style="text-align:center;color:black;">EMPLOYEE INFORMATION</h3>
<?php
 $dbhost = "localhost";
 $dbuser = "GCSADMIN";
 $dbpass = "123456";
 $db = "employee_db";

    $conn = mysql_connect($dbhost, $dbuser, $dbpass,$db);

   if(! $conn ) {
      die('Could not connect: ' . mysql_error());
   }

   $sql = "SELECT EmployeeID,FirstName,MiddleName,LastName,FatherName,SpouseName,MotherName,DOB,Age,BloodGroup,MaritalStatus,Gender,ContactNumber,EmergencyContactNumber,Email,DateOfJoiningatGemini,TotalYearOfExperience,ReleventYearOfExperience,PANnumber,PassportNumber,UANnumber,AadharNumber,PresentAddress,PermanentAddress FROM employee_information";

   mysql_select_db('employee_db');
   $retval = mysql_query( $sql, $conn );
   if(! $retval ) {
      die('Could not get data: ' . mysql_error());
   }
   
   echo "<table border='5px solid block', align='center', width='50%', padding='12px 20px' >";

   while($row = mysql_fetch_assoc($retval, MYSQL_ASSOC)){

     ?>
     
            <tr><th 

Open in new window

0
Hi, this is my index page which I want to pass a number to next page. Php
<a href="next page. Php?id='<?php echo $user_id; ?>
This is nextpage.php
<?php
$user_id=$GET ['id'];
$query=mysqli_query ($conn,"select * from user_tbl where user_id='$user_id'");
It's retrieving all data
But when I press a button for another query in a form then $user_id get empty like this
<form name="entry_form" method="post" action="this page. .php>
<input type="text" name="u_name"><br>
<input type="submit" name="submit_btn" value="insert">
</form>
<?php
If(isset ($_POST ['submitbtn']))
{
$use_name=$_POST ['u_name'];
Mysqli_query($conn,"insert into user_tbl (user_id, user_name) values  ('$user_id', '$user_name')");
?>
When I press submit_btn it takes action on this page and $user_id get empty
Mt problem is I want to use $user_id but not empty tanx.
0
A MySQL  database has three  levels of subtable.
project->snapshot->layer  

Need to duplicate a project record along with all subrecords from snapshot and layer
a project can have many snapshots, a snapshot can have many layers

Would prefer to do this in PHP but stored procedure is OK
All comments and advice welcome and appreciated
0
Hi Experts,

I cannot find this quickly, but can anyone give me an example of file upload form, with I guess PHP on where to save the file?

Thank you
0
<?php
session_start();	
include "database.php";
$sql1 = "SELECT First_Name, Last_Name, Email , Password FROM register WHERE Email = '$_POST[email]'  "; 
$sql2 = "SELECT First_Name, Last_Name, Email , Password FROM register WHERE Phone = '$_POST[phone]'  "; 
$query1 = mysqli_query($conn,$sql1);
$row1 = mysqli_fetch_assoc($query1);
$query2 = mysqli_query($conn,$sql2);
$row2 = mysqli_fetch_assoc($query2);
if(!empty($row1) && !empty($row2))
{
	echo '1';
}
else 
	if(empty($row1) && !empty($row2))
	{
		echo '2';
	}
else 
	if(!empty($row1) && empty($row2))
		{
			echo '3';
		}
else
{
	$otp = mt_rand(100000,999999);
	$hash = md5(mt_rand(0,1000) );
	$pass = md5($_POST["password"]);
	$sql ="INSERT INTO register (First_Name, Last_Name, Email, Password, Phone,Otp,hash) VALUES ('$_POST[fname]','$_POST[lname]','$_POST[email]','$pass','$_POST[phone]','$otp','$hash')";
	$query = mysqli_query($conn,$sql);
	if($query) 
	{
		$_SESSION['login_user']=ucfirst($_POST["fname"])." ".ucfirst($_POST["lname"]);
		$_SESSION['email']=$_POST["email"];
		$to = $_POST["email"];
		$subject = "Email Verification";

		$message  = '<html><body>';
		$message .= '<h1 style="color:#128c7e;">Hello '. ucfirst($_POST["fname"]).' '.ucfirst($_POST["lname"]).'!</h1>';
		$message .= '<p style="color:#080;font-size:18px;">Thanks for signing up!
Your account has been created, you can login with the following credentials after you have activated your account by pressing the url below.<br>
 
------------------------<br>

Open in new window

0
Online Training Solution
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

I'm looking for a PHP code snippet that loops through multiple lines in a textarea and turns it into an unordered list.

For example, users would paste the text similar to the following into a textarea (with a hard carriage return after each line):

Hand carved double wood entry doors
Wood flooring and wood detailed ceiling with custom moldings
Breakfast bar with sink, refrigerator and cabinetry
Large bedroom with views of the Intracoastal Waterway
French doors lead out to a private covered patio with fireplace

Open in new window


.. and I'd like to convert it to the following -- on the fly -- using PHP:

<ul>
     <li>Hand carved double wood entry doors</li>
     <li>Wood flooring and wood detailed ceiling with custom moldings</li>
     <li>Breakfast bar with sink, refrigerator and cabinetry</li>
     <li>Large bedroom with views of the Intracoastal Waterway</li>
     <li>French doors lead out to a private covered patio with fireplace</li>
</ul>

Open in new window


I believe the main challenge is that I have to turn this into some kind of list or array (using the hard carriage returns as delimiters) and to then loop through that list to stiitch everything back together into an unordered list.

How would I accomplish this using PHP?

Thanks,
- Yvan
0
On my php page I have a select statement.  I copied the SQL to SQL Server to test and modify it.

The results are returning in SQL Server and also on the php without the modification.

I added the below to the sql select in PHP (after testing it works in SQL Server).

Original Code
CONVERT(VARCHAR(10), [I].[shipDate], 101),

Open in new window

Modified Code
CASE RIGHT((
		SELECT TOP 1 INV.Name AS InvoiceName 
		FROM SO_Shipment SHIP  
		INNER JOIN SO_Invoice INV ON INV.id_invoice = SHIP.id_invoice
		INNER JOIN SO_Items ITEMS ON ITEMS.id_order = SO.id_order
								  AND ITEMS.id_shipment = SHIP.id_shipment
		WHERE 
		SO.id_order = SO.id_order
		AND RIGHT (INV.Name, 1) = 'B'
		AND ITEMS.Name1 = I.Name1 
		), 1)
	WHEN 'B' THEN
		CONVERT(VARCHAR(10), [I].[shipDate], 101)
	ELSE
		CASE RIGHT([SO].[name], 1)
			WHEN 'B' THEN
				'1/1/3000'
			ELSE
				CONVERT(VARCHAR(10), [I].[shipDate], 101)
			END
	END AS [shipDate]
,

Open in new window

The above SQL returns the desired results.  However, when added to the php page and running I receive my headers but no values.
I modified the Select Case to
'3/1/2017' AS shipDate,

Open in new window

and it returns data in PHP.

I also attempted to create a Stored Procedure in SQL SERVER with the SQL code including the CASE Statement.  It works in SQL Server.

I added the below code to PHP
	$itemsTable = ms_select_table("EXEC [MyDbase].[dbo].[Get_Items];");

Open in new window

Below code shows "0" results with the SQL and SPROC.
	ECHO(COUNT($itemsTable)." unique results.<br />");

Open in new window

Why is the Select Case NOT working in PHP?  How do I get this to work?
0
Hello,

We have come across an issue with PHP open_basedir directive - on 3 of our servers (2 Windows Server 2012 R2 and 1 Windows Server 2016) using the directives throws errors 'open_basedir restriction in effect'. Even for files within the path. We have used it before with no issues. We use per site settings for each site so each site has its own open_basedir directive.
A typical setup looks like this:
[PATH=D:/Websites/name_of_website/www/]
open_basedir=D:\Websites\name_of_website\www
error_log=D:\Websites\name_of_website\www\php_log.txt
upload_tmp_dir=D:\Websites\name_of_website\www\tmp
session.save_path=D:\Websites\name_of_website\www\tmp

Only thing that's changing are the paths.

Any suggestions why it's not working?

P.S. the 3 servers are running PHP 5.6.30 and 7.1.1, the issue happens on both versions.
0
Hi Experts

Could you point how to workaraound this jquery error Uncaught Typerrror: Object values is not a function, acordingly with this code?


This code perfectly runs under most of the browsers:
    $('#last_operation').click(function () {
     
        // This perfectly returns an object
       	$.get("operation/syncronize_date", function(response){
       	    
            var dia_ultima_operacao = Object.values(response)[2];
            var usuario_ultima_replicacao = Object.values(response)[3];
            
  
            $("#ultima_operacao").val(usuario_ultima_operacao + " / "+ dia_ultima_operacao);

    	});
 
    });

Open in new window


But in an server's browser it simply returns the jQuery error.

Could you sugest a workaround code?

Thanks in advance.
0
Hi team,

This is parameshwari, am facing below noted fatal error while am migrating files from local to live server, please can you help me to come out, thanks

Fatal error: Uncaught exception 'PDOException' with message 'could not find driver' in D:\Hosting\13240494\html\matrimony\mike\db_connection.php:2 Stack trace: #0 D:\Hosting\13240494\html\matrimony\mike\db_connection.php(2): 
PDO->__construct('mysql:host=loca...', 'matrimony', '') #1 D:\Hosting\13240494\html\matrimony\mike\mike.php(2): 
require_once('D:\Hosting\1324...') #2 D:\Hosting\13240494\html\matrimony\mike\autoload.php(12):
 require_once('D:\Hosting\1324...') #3 D:\Hosting\13240494\html\matrimony\header.php(1):
 require_once('D:\Hosting\1324...') #4 D:\Hosting\13240494\html\matrimony\index.php(1):
 require_once('D:\Hosting\1324...') #5 {main} thrown in D:\Hosting\13240494\html\matrimony\mike\db_connection.php on line 2

Open in new window


<<Mr Wolfe: Wrapped error in code box >>
0
I need to fetch the results in column but my results are in row how can i modify my code ???
<?php
 $dbhost = "localhost";
 $dbuser = "GCSADMIN";
 $dbpass = "123456";
 $db = "employee_db";

    $conn = mysql_connect($dbhost, $dbuser, $dbpass,$db);

   if(! $conn ) {
      die('Could not connect: ' . mysql_error());
   }

   $sql = "SELECT EmployeeID,FirstName,MiddleName,LastName,FatherName,SpouseName,MotherName,DOB,Age,BloodGroup,MaritalStatus,Gender,ContactNumber,EmergencyContactNumber,Email,DateOfJoiningatGemini,TotalYearOfExperience,ReleventYearOfExperience,PANnumber,PassportNumber,UANnumber,AadharNumber,PresentAddress,PermanentAddress
      FROM employee_information WHERE EmployeeID = 'GI1005'";

   mysql_select_db('employee_db');
   $retval = mysql_query( $sql, $conn );
   if(! $retval ) {
      die('Could not get data: ' . mysql_error());
   }
   
   echo "<table border='5px solid block', width='50%' padding='12px 20px' >";
?>
<tr>
    <th>First Name</th>
    <th>Middle Name</th> 
    <th>Last Name</th>
    <th>Father Name </th>
   </tr>
<?php

   while($row = mysql_fetch_assoc($retval, MYSQL_ASSOC)){

   	 ?>

      <tr>
            <td><?php echo $row['FirstName']; ?></td> 
            <td><?php echo $row['MiddleName']; ?></td> 
            <td><?php echo $row['LastName']; ?></td>
            <td><?php echo $row['FatherName']; ?></td> 
      </tr>

        <?php 
        }
         echo "</table></br></br>";  

Open in new window

Untitled.png
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.