We help IT Professionals succeed at work.

Php empty file

doctorbill
doctorbill asked
on
379 Views
Last Modified: 2014-01-10
The attached file is working perfectly well except for one thing:

I need to get the file to ignore the GTE url if the value is empty

The GET url has 5 possible values sent from a form:
xmlfile1
xmlfile2
xmlfile3
xmlfile4
xmlfile5

If, for example, I only send xmlfile1 and xmlfile2 values from the form, I need the attached page to stop processing after the second value

I have tried using "if(!empty($_GET("xmlfile".$i));" but this does not work
xmlimport-form-loop.php
xmlimport-form-loop.php
Comment
Watch Question

CERTIFIED EXPERT
Expert of the Year 2014
Top Expert 2014
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
Most Valuable Expert 2011
Author of the Year 2014
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
Ray,
Your code on 12/13 works in terms of entering the correct data into the database but the page hangs after the url data is parsed to it and the code from lines 78 onwards does not show on the page

where exactly should the second } bracket be in your code - could you edit the page to demonstrate please
CERTIFIED EXPERT
Expert of the Year 2014
Top Expert 2014
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
Both your code and Ray's cause the same problem:

Code works in terms of entering the correct data into the database but the page hangs after the url data is parsed to it and the code from lines 78 onwards does not show on the page
CERTIFIED EXPERT
Expert of the Year 2014
Top Expert 2014
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
Sorry - your code did not paste correctly
What haappens now is that the page does not hang and the code from 78 onwards runs correctly BUT Ionly send one GET value I get 5 insertions of the same record into the database
CERTIFIED EXPERT
Expert of the Year 2014
Top Expert 2014
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
Sorry - your code did not paste correctly
What haappens now is that the page does not hang and the code from 78 onwards runs correctly BUT Ionly send one GET value I get 5 insertions of the same record into the database

DUMP:
1array(2) { ["xmlfile1"]=> string(30) "Purchase_Order_FI2-4098097.xml" ["xmlsubmit"]=> string(6) "Submit" } 2array(2) { ["xmlfile1"]=> string(30) "Purchase_Order_FI2-4098097.xml" ["xmlsubmit"]=> string(6) "Submit" } 3array(2) { ["xmlfile1"]=> string(30) "Purchase_Order_FI2-4098097.xml" ["xmlsubmit"]=> string(6) "Submit" } 4array(2) { ["xmlfile1"]=> string(30) "Purchase_Order_FI2-4098097.xml" ["xmlsubmit"]=> string(6) "Submit" } 5array(2) { ["xmlfile1"]=> string(30) "Purchase_Order_FI2-4098097.xml" ["xmlsubmit"]=> string(6) "Submit" }
CERTIFIED EXPERT
Expert of the Year 2014
Top Expert 2014
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
<?php 

$dbh = new PDO("mysql:host=localhost;dbname=1callorders", "root", "xxxx");
		
$i = 1;

do {
   echo $i;

if($_GET['xmlfile'.$i]!=""){ // check if the value is empty

$file = $_GET['xmlfile'.$i];

// SKIP THE EMPTY FILE POSITIONS
//if (empty($file)) continue;

$filepath = "xmlimport/";
}

$xml = file_get_contents($filepath . $file);
$obj = simplexml_load_string($xml);

//echo out statements from xml
//$name = (string)$obj->header->manifest->document->name;
//$orderdesc = (string)$obj->body->ORDER->ORDERHEAD->ORDERDESC;
//$orderdesc2 = (string)$obj->body->ORDER->ORDERHEAD->FUNCDESC;

$space = "&nbsp;";
//echo "Name: " . $name . $space;
//echo "Desc: " . $orderdesc . $space;
//echo "Desc2: " . $orderdesc2 . $space;
//end statements
		
//prepare the query
$stmt = $dbh->prepare("INSERT INTO ret_orders (ret_id, ord_prodtpe, ord_prodcdedesc, ord_proddesc) VALUES (:ret_id, :name, :orderdesc, :orderdesc2)");

//bind the named parameter to a PHP variable (called $name and $orderdesc etc )
$stmt->bindParam('ret_id', $ret_id);
$stmt->bindParam('name', $name);
$stmt->bindParam('orderdesc', $orderdesc);
$stmt->bindParam('orderdesc2', $orderdesc2);

$ret_id = "DRM";
$name = (string)$obj->header->manifest->document->name;
$orderdesc = (string)$obj->body->ORDER->ORDERHEAD->ORDERDESC;
//$orderdesc2 = (string)$obj->body->ORDER->ORDERHEAD->FUNCDESC;

//loop through the orderline to get each product description
foreach ($obj->body->ORDER->ORDERLINE as $orderline):
             
	$orderdesc2 = $orderline->PRODUCT->DESCRIPTION;	

	//execute the query
	$stmt->execute();	
endforeach;

//run the second query
//$stmt2 = $dbh->prepare("INSERT INTO ret_orders (ord_linetype) VALUES (:name)");
//$stmt2->bindParam('name', $name);
///$stmt2->execute();

$i++;
} while ($i <= 5);

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body><br /><br />


<?php
$i = 1;
$break = "<br />";
$space = "&nbsp;";

do {
   //echo $i;
if($_GET['xmlfile'.$i]!=""){ // check if the value is empty
$filenames = $_GET['xmlfile'.$i];
}

echo "File Imported:".$space.$filenames.$break;

$i++;
} while ($i <= 5);

?>

</body>
</html>

Open in new window

CERTIFIED EXPERT
Expert of the Year 2014
Top Expert 2014
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
CERTIFIED EXPERT
Expert of the Year 2014
Top Expert 2014

Commented:
Accepting one of your own comments delays the closing process, especially when your comment is not part of the solution.
In this case it would be just easier to split the points between Ray's and my first comments (as you see fit) as they were the solution and the other comments were just clarifications. (Rather than 70 points for every comment ;o)
Most Valuable Expert 2011
Author of the Year 2014

Commented:
@doctorbill: Please, please get some professional programming help, or take some time to step away from this work and learn how to use PHP.  It's not rocket science, but it is extremely detail oriented work, and it takes time and practice to get what you want.  

As an example of what's important but overlooked, you can look no further than the recommendation to change $_GET to $_POST.  I'm concerned that you did not recognize the importance of this recommendation.  We can help with many things, and if you ask more questions along the lines of "what are good learning resources," you will get better results.

Author

Commented:
solution

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.