Jack_son_ used Ask the Experts™
I am creating a PHP web app.  I have a form web file in html.  How can I transfer this with the graphics to PHP?

Thanks in advance
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
If there is no any server-sided script which must be handled with PHP, you can just rename its extension to ".php".
Dave BaldwinFixer of Problems
Most Valuable Expert 2014
If the page does what it is supposed to do already, you don't have to change it to a PHP page.  Is there something else that you want to do on the page that requires PHP?

Here's an example of a page that combines PHP, HTML, and javascript.  Save it as 'Email.php', it will POST to itself.  It's my PHP Email demo that I have posted here many times.


# some settings of POST vars
if (!isset($_POST['send']))  $send = ''; else $send = $_POST['send'];
if (!isset($_POST['toText'])) $toText = ''; else $toText = $_POST['toText'];
if (!isset($_POST['ccText'])) $ccText = ''; else $ccText = $_POST['ccText'];
if (!isset($_POST['subjectText'])) $subjectText = ''; else $subjectText = $_POST['subjectText'];
if (!isset($_POST['msgText'])) $msgText = ''; else $msgText = $_POST['msgText'];
if (!isset($_POST['ccText'])) $ccText = ''; else $ccText = $_POST['ccText'];
if (!isset($_POST['bccText'])) $bccText = ''; else $bccText = $_POST['bccText'];
if (!isset($_POST['nameText'])) $nameText = ''; else $nameText = $_POST['nameText'];
if (!isset($_POST['fromText'])) $fromText = ''; else $fromText = $_POST['fromText'];

if ($send == "") {
    $title="Test Email Page";
else {
	if($fromText === "") die("No name!");
	$title="Test Email Page";
  $announce="Your Message has been Sent!";
	$header = "From: ".$fromText."\r\n";
//	$header .= "Cc: ".$ccText."\n";
	$header .= "Reply-To : ".$fromText."\r\n";
	$header .= "Return-Path : ".$fromText."\r\n";
	$header .= "X-Mailer: PHP\r\n";
	$header .= "MIME-Version: 1.0\r\n";
	$header .= "Content-Type: text/plain; charset=iso-8859-1\r\n";
//	ini_set(sendmail_from,$fromText);  
	mail($toText, $subjectText, $msgText, $header, '-f'.$fromText);
//	ini_restore(sendmail_from);
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title><?php echo($title)?></title>
<style type="text/css">
A:link { color: #999999; }
A:visited { color: #999999; }
A:hover {color: #0099ff;}
<script type="text/javascript">
function check()
var at=document.getElementById("fromText").value.indexOf("@");
var eml=document.getElementById("fromText").value;
var nam=document.getElementById("nameText").value;
var alerttxt="";
var submitOK="true";

if (eml.length < 5 || at == -1)
    alerttxt=alerttxt+"Please enter a valid e-mail address!\r\n";
    //return false;
if (nam.length < 3)
    alerttxt=alerttxt+"Please enter your name.\r\n";
    //return false;
if (submitOK=="false")
    return false;

// -->

<body bgcolor="#ddeedd">
<div align="center">
<table border="0" cellpadding="0" cellspacing="0" summary="" width="580">
<tr><td align="center">

if ($send != "") {
   	echo ("To: ".$toText."<br>\r\nSubject: ".$subjectText."<br>\r\n".$msgText."<br>\r\n".$header);

<p><b><font color="#000000" size="5">Test Email</font></b></p>
<font size="4" color="#000000">

<form method="POST" action="Email.php" onsubmit="return check();">
    <p><font size="3"><b>Name: <input type="text" name="nameText" id="nameText" size="46"></b></font></p>
    <p><font size="3"><b>Email: <input type="text" name="fromText" id="fromText" size="46"></b></font></p>
    <input type="hidden" name="subjectText" value="Web Mail">
    <p><font face="Arial" size="3"><b>Message Text:</b></font></p>
    <p><font face="Arial" size="3"><b><textarea rows="6" name="msgText" cols="60"></textarea></b></font></p>
    <p><font size="3"><b><input type="submit" value="Send" name="send" style="font-family: Arial; font-size: 12pt; font-weight: bold"></b></font></p>
    <input type="hidden" name="state" value="1">
  <b><font face="Arial" size="4" color="#e00000"><?php echo($announce)?></font></b><br><br>



Open in new window

If you want to convert html to php, you can paste your html code into the box which includes following web sites, then convert it to php code :) The web site link: or
JavaScript Best Practices

Save hours in development time and avoid common mistakes by learning the best practices to use for JavaScript.


Thanks everyone.  The site right now is static, mainly to design the pages.  I will need this to be more interactive, to store data in mysql, etc.    So either just changing the pages to .php with one of the steps above?
You will need to define what "more interactive" means with actual use cases of what data you want to collect and what you want to do with it.
Most Valuable Expert 2011
Top Expert 2016
Executive summary:   PHP is used to generate HTML.  So copy all your HTML statements into well-organized files and use PHP to read the files, then echo the output to the browser.  Once you have this part working, you can begin to add the dynamic functionality of the data base.

Buy this book and give yourself time to read it and work through the examples.  It will not make you a pro, but it is easy to read and comes with a downloadable code library that you can copy and adapt for your own needs.

Best of luck with your project, ~Ray
Dave BaldwinFixer of Problems
Most Valuable Expert 2014
I just got that book and I'm working thru it.  As Ray says, PHP is used to generate HTML but also to do things that HTML can't.  I think it is well demonstrated in my PHP Email demo I posted above.
Software Developer
In regard of graphics php doesn't change. Your graphics stay separate files and you display them the same html you now have.

For what php is added typically is putting together static and dynamic parts of your pages, eg loading a static page template and adding in the html for a certain product or whatever your webapp is about, via intreractivly chosen product id.

The php is also used for processing form input, by letting the form action call a php script. That can also be the same php script, which had output the html form, like in Dave Baldwin 's nice mail sample. Your php script then get's the form data in an array $_POST, if the form method was set to POST. Or $_GET, if the form method was GET. You could also always process a combined array called $_REQUEST.

Simply create the following php script showformdata.php as a simple start:
<?php print_r($_REQUEST); ?>

Open in new window

Put that php script into the same dir as the html page.

In one of your html pages with an html form, you may now have an action like "mailto:yourmailadress@yourprovider.tld". Change that to call the php script as in:
...<form method="POST" action="showformdata.php">...

Open in new window

Enter data into your form and submit it, the php script then will show your input as it's output. This way you know what arrives in php and can then extend to save data into mysql, compute things, query other data and output that.

Next steps would be to change the php script to not just print the input, but do something with it, eg store it into a mysql database or create a html response page on condition of the input data.

Dave's example is quite complete, as it has a form, processes the $_POST after that form is submitted and also has javascript in it, which checks the form input, before it is submitted as a request to the server again.

You will need to use a combination of html, php code and javascript code in general, to create a dynamic webapp of your now static html pages.

Bye, Olaf.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial