Change HTML page with Java script to PHP page issues

Hi
My page is in HTML with java script called test.html.

When I open it in Dreamweaver and save it as a .php page and open the file in a web browser it just shows text the java doesn't work any more.

The reason I want the test.html changed to  test.php  is so I can add the PHP script from printphppage.php to the textarea of the test page. all my pages are attached below thanks for your help

Temp.zip
paddy086Asked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
John EastonConnect With a Mentor DirectorCommented:
Are you opening the file directly?  I.e. your browser address bar shows something like:  C:\Downloads\Temp\printphppage.php

If so, the page is not being passed to PHP.  You normally need a webserver to process the PHP pages and then output HTML to the browser.  I don't use Dreamweaver, but some IDEs have integrated PHP processors you could use, otherwise you need to run the files from a webserver setup to use PHP (IIS comes on Windows PCs, not sure about Macs).
0
 
Ray PaseurCommented:
@JEaston: Macs can use MAMP to create an all-in-one web server.  Fast and easy to use :-)
http://www.mamp.info/en/
0
 
Julian HansenCommented:
You don't have to open and save - you can just rename

test.html => rename to test.php

If you have a PHP interpreter setup on your web server this should be enough to have it parse your file.

You can then add php code directly to this file.

If after a rename you are not getting expected results then as JEaston mentioned you probably don't have anything setup to interpret PHP
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
paddy086Author Commented:
Hi I am running a local Webserver XAMPP.

My test.html page has 3 text boxes that use PrintLabelnew.js to enable printing on a DYMO printer.

test.html
<!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>Print a Label</title> 
<script src = "http://labelwriter.com/software/dls/sdk/js/DYMO.Label.Framework.latest.js" type="text/javascript" charset="UTF-8"> </script>
<script src = "PrintLabelnew.js" type="text/javascript" charset="UTF-8"> </script>
</head>

<body>
<h1>DYMO Label Framework JavaScript Library Samples: Print Label test 2</h1> 


    <div id="printDiv">
	<label for="textTextArea">Label text:</label><br/>
        <textarea name="textTextArea" id="1textTextArea"  rows='5' cols='40'></textarea>
            <button id="1printButton" onclick="print1();return false;">Print</button>
        </div>
		
        <div id="printDiv">
		<label for="textTextArea">Label text:</label><br/>
        <textarea name="textTextArea" id="2textTextArea"  rows='5' cols='40'></textarea>
            <button id="2printButton" onclick="print2();return false;">Print</button>
        </div>
        <div id="printDiv">
		<label for="textTextArea">Label text:</label><br/>
        <textarea name="textTextArea" id="3textTextArea"  rows='5' cols='40'></textarea>
            <button id="3printButton" onclick="print3();return false;">Print</button>
        </div>
        <div id="printAll">
            <button id="printAllBtn" onclick="print1(); print2(); print3(); return false">Print All</button>
        </div>

</body> 
 
</html>

Open in new window


PrintLabelnew.js
function printStuff(what)
{
            try
            {
                // open label
                var labelXml = '<?xml version="1.0" encoding="utf-8"?>\
    <DieCutLabel Version="8.0" Units="twips">\
        <PaperOrientation>Landscape</PaperOrientation>\
        <Id>Address</Id>\
        <PaperName>30252 Address</PaperName>\
        <DrawCommands/>\
        <ObjectInfo>\
            <TextObject>\
                <Name>Text</Name>\
                <ForeColor Alpha="255" Red="0" Green="0" Blue="0" />\
                <BackColor Alpha="0" Red="255" Green="255" Blue="255" />\
                <LinkedObjectName></LinkedObjectName>\
                <Rotation>Rotation0</Rotation>\
                <IsMirrored>False</IsMirrored>\
                <IsVariable>True</IsVariable>\
                <HorizontalAlignment>Left</HorizontalAlignment>\
                <VerticalAlignment>Middle</VerticalAlignment>\
                <TextFitMode>ShrinkToFit</TextFitMode>\
                <UseFullFontHeight>True</UseFullFontHeight>\
                <Verticalized>False</Verticalized>\
                <StyledText/>\
            </TextObject>\
            <Bounds X="332" Y="150" Width="4455" Height="1260" />\
        </ObjectInfo>\
    </DieCutLabel>';
                var label = dymo.label.framework.openLabelXml(labelXml);

                // set label text
                label.setObjectText("Text", what);
                
                // select printer to print on
                // for simplicity sake just use the first LabelWriter printer
                var printers = dymo.label.framework.getPrinters();
                if (printers.length == 0)
                    throw "No DYMO printers are installed. Install DYMO printers.";

                var printerName = "";
                for (var i = 0; i < printers.length; ++i)
                {
                    var printer = printers[i];
                    if (printer.printerType == "LabelWriterPrinter")
                    {
                        printerName = printer.name;
                        break;
                    }
                }
                
                if (printerName == "")
                    throw "No LabelWriter printers found. Install LabelWriter printer";

                // finally print the label
                label.print(printerName);
            }
            catch(e)
            {
                alert(e.message || e);
            }
}
function print1()
{
    var textTextArea = document.getElementById('1textTextArea');
    printStuff(textTextArea.value);
}
function print2()
{
    var textTextArea = document.getElementById('2textTextArea');
    printStuff(textTextArea.value);
}
function print3()
{
    var textTextArea = document.getElementById('3textTextArea');
    printStuff(textTextArea.value);
}

Open in new window


On LINE 16 of test.html
       
<textarea name="textTextArea" id="1textTextArea"  rows='5' cols='40'></textarea>

Open in new window

I inserted my php script just in-between   cols='40'>PHP-SCRIPT</textarea>

<?php 
 $con = mysqli_connect("localhost","root","PASSWORD","test"); 
 // Check connection 
 if (mysqli_connect_errno()) 
 { 
 echo "Failed to connect to MySQL: " . mysqli_connect_error(); 
 } 

$result = mysqli_query($con,"SELECT w1monsick2.*, w1monsick1.* FROM w1monsick2, w1monsick1 WHERE w1monsick2.id2 =2 = w1monsick1.id =1"); 

 
$tr1= '<tr><td>Date</td>';
$tr2= '<tr><td>Sick Teacher</td>';
$tr3= '<tr><td>Period</td>';
$tr4= '<tr><td>Cover Teacher</td>';
$tr5= '<tr><td>Subject</td>';
$tr6= '<tr><td>Class</td>';
$tr7= '<tr><td>Room</td>';
 
  echo "<table border='1' height='50' font size='20'> 

 "; 

 while($row = mysqli_fetch_array($result)) 
 { 
 
 $tr1 .="<td>" . $row['datepicker'] . "</td>"; 
 $tr2 .="<td>" . $row['sickteacher2'] . "</td>"; 
 $tr3 .="<td>" . $row['period2'] . "</td>"; 
 $tr4 .= "<td>" . $row['coverteacher2'] . "</td>"; 
 $tr5 .= "<td>" . $row['subject2'] . "</td>"; 
 $tr6 .= "<td>" . $row['class2'] . "</td>"; 
 $tr7 .= "<td>" . $row['room2'] . "</td>"; 
 } 
 $tr1 .= '</tr>';
 $tr2 .= '</tr>';
 $tr3 .= '</tr>';
 $tr4 .= '</tr>';
 $tr5 .= '</tr>';
 $tr6 .= '</tr>';
 $tr7 .= '</tr>';

 echo 
 $tr1,'
 ',$tr2,'
 ',$tr3,'
 ',$tr4,'
 ',$tr5,'
 ',$tr6,'
  ',$tr7,'
 </table>';  

 mysqli_close($con); 
 ?> 

Open in new window

0
 
Chris StanyonConnect With a Mentor Commented:
Having XAMMP installed is not enough - you need to serve your page through it, so in your browser you would typically type something like: localhost/printphppage.php

Before trying to debug your script, create a very simply php page and try that. It only needs to contain some basic php code - something like:

<?php
echo "Hello World";
?>

Open in new window

If that works, you're heading in the right direction - if not, then it's likely to be your XAMPP setup and not your PHP file that's the problem.

FYI - Your SQL query looks a little off, but first things first :)
0
 
paddy086Author Commented:
JEaston I now get what you were saying sorry I didn't understand it earlier  

Chris Stanyon you were correct as well
my script is working now when I renamed the test.html to test.php  and actually placed it into my localhost directory it worked I should have know that sorry

There is one issue now in the text area my php script dose work as far as it prints the info from my data base but it also
prints the Table structure e.g at the  <tr> <td>  <tr> <td> on the label
0
 
paddy086Author Commented:
I am marking  this question as answered as the experts have answered my original question correctly. But I will be opening a new question on my second issue
0
All Courses

From novice to tech pro — start learning today.