By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,968 Members | 1,684 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,968 IT Pros & Developers. It's quick & easy.

find and Exec statment in PHP not working

100+
P: 123
Hi All,
I have a page in which user can enter first name,last name , date and according to that My script should search for the records which matches the above last n first names and print it.
I have the below code,
But seems not working..
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $title = " Form";
  3. echo "Hello";
  4.  if(isset($_POST['fname'])) { $f1 =  $_POST['fname']; }
  5.  
  6. if (isset($_POST['lname'])) { $ll =  $_POST['lname']; }
  7. if (isset($_POST['add'])) { $a1 =  $_POST['add']; }
  8. if (isset($_POST['date'])) { $d1 =  $_POST['date']; }
  9.  
  10. $fullname = $l1.","f1;
  11. echo "$fullname;
  12. $dirname = "/home/gr/ereports/O1"  ;
  13.  
  14. $handle = opendir($dirname) or print "cant open";
  15.  
  16. $ans = shell_exec("find /home/gr/ereports/O1/$d1 -name \*.ps  -exec grep -i -e "$fullname" {} \;  -print; ");
  17.  
  18. ?>
  19.  
  20.  
If i go on shell to home/gr/ereports/O1 and then write the code as below
Expand|Select|Wrap|Line Numbers
  1. find dirname -name "*.ps" -exec grep -i -e "CAK, SO" {} \; -print ;
  2.  
Here in above "CAK , SO" in which CAK is the lastname n SO is the first name
its giving me the result perfectly.
I am thinking that the way I used the above statment in PHP is wrong..
Can anybody help me...
Thanks
Sep 12 '08 #1
Share this Question
Share on Google+
3 Replies


Atli
Expert 5K+
P: 5,058
Hi.

There are a lot of syntax errors in that code.
Try turning on the debug messages and fix the errors. See if that helps.
Sep 13 '08 #2

100+
P: 123
Hi..
Oh m sorry..have posted that with making some changes..And thus , it has so many syntax errors..
When I execute the below on shell it works fine...
Expand|Select|Wrap|Line Numbers
  1. find /home/gr/ereports/O1/2008-06-17 -name "*.ps" -exec grep -i -e "LISA" {} \; -print ;
  2.  
And in PHP i am writing
Expand|Select|Wrap|Line Numbers
  1. $ans = shell_exec("find /home/gr/ereports/O1/$d1 -name /"/*.ps/"  -exec grep -i -e $l1  {} \;  -print; ");
  2.  
How can I write "*.ps" in shell_exec ..here I have used /"/*.ps/" back slashes..
Sep 16 '08 #3

pbmods
Expert 5K+
P: 5,821
Heya, AJD.

Use these slashes: \ to escape quotes.
Sep 16 '08 #4

Post your reply

Sign in to post your reply or Sign up for a free account.