We help IT Professionals succeed at work.

Include Java in a PHP application

jana
jana asked
on
1,417 Views
Last Modified: 2013-12-14
With the help of EEs, I just finished an HTML that works excellently picking dates.  Unfortutanetly, I just discover that the routins of the date-picking is not for a HTML file, its for a PHP file.  I can't re-write for HTM and add the date-picking, but I would like to include in the PHP application the newly scripts.

I'm trying various forms with no success.  Here is the code in HTML that I woul like to include in PHP:
(can it be done)

<head>
      <title>jQuery UI Datepicker - Format date</title>
      <link type="text/css" href="ui.all.css" rel="stylesheet" />
      <script type="text/javascript" src="jquery-1.3.2.js"></script>
      <script type="text/javascript" src="ui.core.js"></script>
      <script type="text/javascript" src="ui.datepicker.js"></script>
      <link type="text/css" href="demos.css" rel="stylesheet" />
      <script type="text/javascript">
      $(function() {
        $("#From").datepicker({ dateFormat: 'yy-mm-dd' });
        $("#To").datepicker({ dateFormat: 'yy-mm-dd' });
      });
      </script>
</head>
<body>

<div class="demo">

<p>From: <input type="text" id="From"></p>
<p>To: <input type="text" id="To"></p>
Comment
Watch Question

Top Expert 2008

Commented:
Yes, you can include the html and javascript from PHP. It is a very common thing to do. I would do something like this:

Save the code above up to and including <body> as "datepicker_head.html". Write your PHP file like this:
<hmtl>
<?php include('datepicker_head.php');?>
<div class="demo">
 
<p>From: <input type="text" id="From"></p>
<p>To: <input type="text" id="To"></p>

Open in new window

Author

Commented:
I want to include or import HTML and JAVA to PHP, not from it.  The code provided above is HTML and I want my PHP application to run those instructions.
Top Expert 2008

Commented:
How will this PHP application be used? Is it to be run in a browser?

A php file can contain "normal" html code, including <script> tags and javascript. If the file extension is .php the web server will parse anything between <?php ?> tags as PHP code, anything outside those tags will be sent directly to the browser as HTML.

Java is not involved here. Java and Javascript are two separate programming languages.

Author

Commented:
So the script I placed at the initial at the question can't be included in a PHP application?

I have a PHP program where it asks for dates.  I found a Datepicker and tested and run it but when I finished it, I remember that the dates field is in a PHP apps not in a HTML apps.  The script at top is HTML.  That HTML calls *.js... (see above)

Any suggestions?
Top Expert 2008

Commented:
>> So the script I placed at the initial at the question can't be included in a PHP application?

That is not a script, it is a html snippet. And yes, it CAN be included into a PHP script, using the include() function like I showed you in my first reply.

You did not answer my questions: How will this PHP application be used? Is it to be run in a browser?

Author

Commented:
By your first reply I assume that you think I want to have a HTML incluide a PHP; Its the other way around.  I have a PHP apps that I want to use the HTML statements (the one I placed at my question).  In other words, how can I have those instruction within my PHP.

Ok.  The PHP application is currently being used thru browser and it asks the user for dates.  The HTML at top is a apps I developed with the help of the EE to pick dates.  I wanted to modify my PHP in order for the user to pick dates.  But when I finished with EE, I noticed the application is under HTML and the apps I am using is under PHP.

Hope I made a clearer statement of what I want.
Top Expert 2008
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
Ok, since I need this HTML code withing my PHP file, I can just write the PHP section in my HTML and that way I can have my PHP features and also my HTML DatePicker all in  one file (only keep the PHP code within "<?php?" and "?>")?

If that's the case, and I can successfully embed in my HTML datepicker code, the PHP portions, how to I transfer the Date Fields values to the PHP section?
Top Expert 2008
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
Prior working with the HTML file, with DatePicker, my solutions was based on 2 PHP files.

The First File (InputDate.php):

Ask the ClientID (load from MySql table the IDs), and asks for the "From" "To" dates. In this PHP file I have the   form action="ShowResults.php" method="post"> statement

On the second file (ShowResults.php):

I has the "$From = strtotime($_POST['From'])" lines (for both dates and ClientID).

At end, my application is already like that.   So in my first file "InputDate.php", I can include the actual statements of the HTML but not include them within "<?php?" and "?>")?



Top Expert 2008

Commented:
That should work, yes.

Author

Commented:
sounds good...I'll try!

Author

Commented:
It didn't work.

First I change the extention to PHP in my HTML file (which I have datepicker see HTML lines with my question) and ranned and it worked perfectly.

Then I copied my PHP contents and placed all within "<?php?" and "?>" (to open up MySql and ask uder which client to shoose).

So now the file should look ike this:

<!doctype html>
html lines...
html lines... (lines for running for showing title & info
html lines...
html lines...

<?php
php lines...
php lines...
php lines... (lines for accessing MySQL and showing drop-down selections: select client)
php lines...
?>

html lines...
html lines... (lines with DatePicker fields and user select "From" and "To" dates to use)
html lines...
html lines...

<?php
php lines...
php lines...
php lines... (lines for running the ShowServiecesLog.php file - actual report apps)
                     <form action=ShowServicesLog.php method=post>
php lines...
?>

</body>
</html>
------ this is the end.

What am I missing?

I want to use my PHP file and also the HTML file
Top Expert 2008
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
Question:

1. Starting my PHP with HTEML tags ok? (as I showed previouls)?

2. Do you recommend to start as HTML or PHP?  And if HTML, what should be the first line (and vice-versa)?

2. The error message I get is "Parse error: parse error, expecting `','' or `';'' in
     /home/www/msys/a/zSAMPLE.DatePicker.php on line 40"

The "lines for running the ShowServiecesLog.php file", does'nt produce html output since I get the parse error (but in my original; PHP, it does display results perfectly)





Top Expert 2008
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
Done & it works perfectly!

This new PHP file you help me combine inputs data from user and then transfers them to a secin PHP file (""ShowServiecesLog.php"") thats displays the results.  I can't seem to send the Dates values to the "ShowServiecesLog.php" file (every other variable does goes to the file except the dates).

Before combining the DatePicker and PHP file, the Date input was like this:

<input type='text' name='From'> - From Date (YYYY-MM-DD)<br />
<input type='text' name='To'> - To Date (YYYY-MM-DD)<br />

After combining the HTML and PHP, the Date input is like this:

$("#From").datepicker({ dateFormat: 'yy-mm-dd' });
$("#To").datepicker({ dateFormat: 'yy-mm-dd' });

I have no errors now, it works perfectly, it just the Date values entered by the user is not transfer to the "ShowServiecesLog.php".

Am I missing something?

Author

Commented:
I just saw the difference: the "input type" lines.

Prior combining, I had:

   <input type='text' name='DateFrom'><br />
   <input type='text' name='DateTo'><br />

With DatePicker, its:

<p><input type="text" id="DateFrom"></p>
<p><input type="text" id="DateTo"></p>

Can this be it?

Author

Commented:
I just tried and change the "ID=" to "NAME=" and DatePicker didn't work.

Any suggestion?
Top Expert 2008
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
U R THE MASTER!!!!!  THANX!!!

If I could give u mire point I would!!!

Author

Commented:
EXCELLENT !!
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.