Passing data back to .html file

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
wep
Forum Newbie
Posts: 2
Joined: Wed Dec 06, 2006 1:38 pm

Passing data back to .html file

Post by wep »

I have a site already written with html. Now that I've learned some php I want to open a data file with php code, read in the text and pass it back to the calling website to display it. I've been able to easily send data from forms, text boxes etc. to a php program but not the other way round. Any help?

Thanks!
Bill
User avatar
ok
Forum Contributor
Posts: 393
Joined: Wed May 31, 2006 9:20 am
Location: The Holy Land

Post by ok »

You need to use JS for this purpose. Some code I wrote in quickly:

Code: Select all

<script type="text/javascript">
var temp = location.search;

var idx2_data1;
var idx2_data2;
if(temp)
{
   var idx1_data1 = temp.indexOf("?data1=");
   var idx1_data2 = temp.indexOf("&data2=");

   if ((idx1_data2 >= 0)&&(idx1_data1 >= 0))
   {
        //The size of idx1_data1
	idx1_data1 += 7;
        //The size of idx1_data2
	idx1_data2 += 7;

	var idx2_data2 = temp.indexOf("&", idx1_data2);
	var idx2_data1 = temp.indexOf("&", idx1_data1);
 	if (idx2_data2 > 0) { data2 = temp.substring(idx1_data2, idx2_data2); } else { data2 = temp.substring(idx1_data2); }  
	if (idx2_data1 > 0) { data1 = temp.substring(idx1_data1, idx2_data1); } else { data1 = temp.substring(idx1_data1); }  
   }
}
document.writeln('<font color="#cc0000"><b>Data1:</b></font> '+data1);
document.writeln('<font color="#cc0000"><b>Data2:</b></font> '+data2);
</script>
You can find tutorial about JS in: http://www.w3schools.com/js/default.asp
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Re: Passing data back to .html file

Post by RobertGonzalez »

wep wrote:I have a site already written with html. Now that I've learned some php I want to open a data file with php code, read in the text and pass it back to the calling website to display it. I've been able to easily send data from forms, text boxes etc. to a php program but not the other way round. Any help?

Thanks!
Bill
This does not require the use of Javascript at all. Use the PHP filesystem functions mixed with what you already know about displaying data to the screen.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: Passing data back to .html file

Post by John Cartwright »

wep wrote:I have a site already written with html. Now that I've learned some php I want to open a data file with php code, read in the text and pass it back to the calling website to display it. I've been able to easily send data from forms, text boxes etc. to a php program but not the other way round. Any help?

Thanks!
Bill
Why not have php process both pages?
wep
Forum Newbie
Posts: 2
Joined: Wed Dec 06, 2006 1:38 pm

Re: Passing data back to .html file

Post by wep »

Jcart wrote:
wep wrote:I have a site already written with html. Now that I've learned some php I want to open a data file with php code, read in the text and pass it back to the calling website to display it. I've been able to easily send data from forms, text boxes etc. to a php program but not the other way round. Any help?

Thanks!
Bill
Why not have php process both pages?
I have done that and all works great. I just thought there should be a way to do it as described and if there is a way (without JS) then I should learn about it.

Thanks a lot for responding.

Bill
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Static HTML can't pull jack if it doesn't have Javascript to do it as there aren't any native controls to pull in information from anywhere. Sticking to PHP works perfectly fine in this, so don't sweat it. :)
Post Reply