Results 1 to 14 of 14
  1. #1
    Join Date
    Feb 2004
    Location
    Irving, TX (Dallas, Fort Worth)
    Posts
    379

    Unanswered: Quick Screen Write Question

    How do I write to the current screen or browser session?

    Echo/Print always open a new session and I need to write to the current one.

    I am setting a var in another .php that is called by my Form action= statement and it is processing OK but can't get the screen resfresh right.

    Help Please!

    DBS4M

  2. #2
    Join Date
    Apr 2005
    Location
    Baltimore, MD
    Posts
    297
    To write a variable to a webpage, you just use echo $var;
    I'm assuming you're trying to do something else? Could you post some of your code?

    (p.s. by 'session', do you mean the browser window?)

  3. #3
    Join Date
    Feb 2004
    Location
    Irving, TX (Dallas, Fort Worth)
    Posts
    379

    You Bet!

    Quote Originally Posted by jfulton
    To write a variable to a webpage, you just use echo $var;
    I'm assuming you're trying to do something else? Could you post some of your code?

    (p.s. by 'session', do you mean the browser window?)
    HTML code which is an include file to a .SHTML file.
    Code:
    <?php
        include("dd-process.php");
        ?>
        <html>
        <head>
        
        </head>
        
        <body bgcolor=white lang=EN-US link=black vlink=black>
        <table border=0 width=500 cellspacing=0 cellpadding=0 align=center height=400 width=800>
        	<form method=post action="dd-process.php" name=parts>
        	<tr height=20>
        	<td valign=top bgcolor="#ffffff">
        	<center>
        	<font face="Verdana" size="4"><b>My Title</b></font>
        	<br>
        	<font face="Verdana" size="3">Parts Catalog</font>
        	<br>
        	<font face="Verdana" size="3"><b>Category:</b></font>
        	</td>
        	</tr>
        
        	<tr height=5>
        	<td height=5>&nbsp;</td>
        	</tr>
        
        	<tr height=30>
        	<td align=center valign=top>
        	<SELECT NAME="Type">
        		<OPTION SELECTED>
        		<OPTION value="Bkt">Buckets
        		<OPTION value="Fan">Fans - Cooling
        		<OPTION value="Air">Filters - Air, Lube, Industrial
        		<OPTION value="Fld">Fluids
        		<OPTION value="Hrd">Hardware
        		<OPTION value="Int">Intake/Exhaust Systems
        		<OPTION value="Pre">Pre-Cleaning - Air
        		<OPTION value="Scr">Scrapers
        		<OPTION value="Tee">Teeth
        		<OPTION value="Tir">Tires
        		<OPTION value="Tol">Tools - Ground Engaging
        		<OPTION value="Use">Used Parts
        	</SELECT>
        	<br>&nbsp;<br>
        	<input type=submit name=Prc value=Get>
        	</td>
        	</tr>
        
        	<tr height=5>
        	<td height=5>&nbsp;</td>
        	</tr>
        
        	<tr>
        	<td>
        	<table border=5 height=300>
        	<! Write the table elements from the PHP script!  >
        	<?php 
        		echo "Found Table!"; 
        		echo $mid_block; 
        	?>
        	</table>
        	</td>
        	</tr>
        	</form>
        </table>
        </body>
        </html>
    PHP script code
    Code:
    <?php
       $mid_block = "<tr><td>&nbsp;</td></tr>";
       if ($_POST["Type"] == 'Fan') {
       	echo "Found Fan!";
       	$mid_block = "
       		<tr>
       		<td rowspan=3 width=25%>
       		<img src='./Images/flexxairefan.gif'>
       		</td>
       		<td colspan=2 width=75%>
       		<font face=Verdana size=3>
       		<b>Cooling Fans by&col;
       		</td>
       		</tr>
       
       		<tr>
       		<td>
       		<font face=Verdana size=3><ul>FlexxAire</ul>
       		</td>
       		</tr>
       
       		<tr>
       		<td>
       		<font face=Verdana size=3><ul>SandVik</ul>
       		</td>
       		</tr>
       	";
       } elseif ($_POST["Type"] == 'Air') {
       	echo "Found Air!";
       	$mid_block = "
       		<tr>
       		<td rowspan=3 width=25%>
       		<img src='./Images/luberfiner.jpg'>
       		</td>
       		<td colspan=2 width=75%>
       		<font face=Verdana size=3>
       		<b>Cooling Fans by&col;
       		</td>
       		</tr>
       
       		<tr>
       		<td>
       		<font face=Verdana size=3><ul>FlexxAire</ul>
       		</td>
       		</tr>
       
       		<tr>
       		<td>
       		<font face=Verdana size=3><ul>SandVik</ul>
       		</td>
       		</tr>
       	";
       }
       ?>
    This process OK as I see the "Found <value>" statement, but in a new session, which blanks the original browser session and writes just the echo value.

    Need this to write In place when the button is clicked/activated. Since this is part of an included file the orginal must stay in place.

    Tried leaving out the echo(s) but saw no processing, included to check processing. I also look through the online PHP help to see if there was a refresh command so my inline echo would refresh it's value, but could not find anything on refresh.

    If you need I can include a generic stripped version of the .SHTML file as well, which is the template file. This whole thing writes into a non-frame text area on the page.

    Wanted to do buttonless but settled on the button as I could not find anything to support other activities unless I added a Java Script.

    DBS4M

  4. #4
    Join Date
    Apr 2005
    Location
    Baltimore, MD
    Posts
    297
    You want to send the form data to the current page, not "dd-process.php". Try changing
    <form method=post action="dd-process.php" name=parts>
    to
    Code:
    <form method=post action="*CURRENT WEB PAGE.shtml*" name=parts>
    <!-- OR I'm pretty sure you can just use: -->
    <form method=post action="" name=parts>

  5. #5
    Join Date
    Feb 2004
    Location
    Irving, TX (Dallas, Fort Worth)
    Posts
    379

    Does't Work

    Quote Originally Posted by jfulton
    Code:
    <form method=post action="*CURRENT WEB PAGE.shtml*" name=parts>
     <!-- OR I'm pretty sure you can just use: -->
     <form method=post action="" name=parts>
    I get the error:

    Method Not Allowed

    The requested method POST is not allowed for the URL /parts.shtml.
    Also get this if I set action=parts-cm.html for the included html file.

    Do I need to invoke GET instead of POST?

    DBS4M

  6. #6
    Join Date
    Apr 2005
    Location
    Baltimore, MD
    Posts
    297
    GET and POST are just ways of sending the form information. ACTION should be set to the webpage which is going to be processing and displaying the results of the form information. If you switch the form method, you should access it the same way in php (ie. $_GET or $_POST -- I also believe $_REQUEST will handle both.)

    Make sure that the page processing your info is correct. The script should work when you set action to "dd-process.php" (output should be something like "Found Air!...table html")

    If that works, then there's probably something wrong in your "action" page. (This can be kind of tricky if you're using frames too.)

  7. #7
    Join Date
    Feb 2004
    Location
    Irving, TX (Dallas, Fort Worth)
    Posts
    379

    Code Update

    I only sent a partial of the php code before so here is final with all options:
    Code:
    $mid_block = "";
       if ($_POST["Type"] == 'Fan') {
       	echo "Found " . $_POST["Type"];
       	$mid_block = "<IFRAME width=500 height=350 src="./parts-fan.html"></IFRAME>";
       }
       if ($_POST["Type"] == 'Air') {
       	echo "Found " . $_POST["Type"];
       	$mid_block = "<IFRAME width=500 height=350 src="./parts-air.html"></IFRAME>";
       }
       if ($_POST["Type"] == 'Bkt') {
       	echo "Found " . $_POST["Type"];
       	$mid_block = "<IFRAME width=500 height=350 src="./parts-bkt.html"></IFRAME>";
       }
       if ($_POST["Type"] == 'Fld') {
       	echo "Found " . $_POST["Type"];
       	$mid_block = "<IFRAME width=500 height=350 src="./parts-fld.html"></IFRAME>";
       }
       if ($_POST["Type"] == 'Hrd') {
       	echo "Found " . $_POST["Type"];
       	$mid_block = "<IFRAME width=500 height=350 src="./parts-hrd.html"></IFRAME>";
       }
       if ($_POST["Type"] == 'Int') {
       	echo "Found " . $_POST["Type"];
       	$mid_block = "<IFRAME width=500 height=350 src="./parts-int.html"></IFRAME>";
       }
       if ($_POST["Type"] == 'Pre') {
       	echo "Found " . $_POST["Type"];
       	$mid_block = "<IFRAME width=500 height=350 src="./parts-pre.html"></IFRAME>";
       }
       if ($_POST["Type"] == 'Scr') {
       	echo "Found " . $_POST["Type"];
       	$mid_block = "<IFRAME width=500 height=350 src="./parts-scr.html"></IFRAME>";
       }
       if ($_POST["Type"] == 'Tee') {
       	echo "Found " . $_POST["Type"];
       	$mid_block = "<IFRAME width=500 height=350 src="./parts-tee.html"></IFRAME>";
       }
       if ($_POST["Type"] == 'Tir') {
       	echo "Found " . $_POST["Type"];
       	$mid_block = "<IFRAME width=500 height=350 src="./parts-tir.html"></IFRAME>";
       }
       if ($_POST["Type"] == 'Tol') {
       	echo "Found " . $_POST["Type"];
       	$mid_block = "<IFRAME width=500 height=350 src="./parts-tol.html"></IFRAME>";
       }
       if ($_POST["Type"] == 'Use') {
       	echo "Found " . $_POST["Type"];
       	$mid_block = "<IFRAME width=500 height=350 src="./parts-use.html"></IFRAME>";
       }
    Also modified the following from:
    Code:
    	<tr>
       	<td>
       	<table border=5 height=300>
       	<! Write the table elements from the PHP script!  >
       	<?php 
       		echo "Found Table!"; 
       		echo $mid_block; 
       	?>
       	</table>
       	</td>
       	</tr>
    to:

    Code:
    	<tr>
       	<td>
       	<! Write the table elements from the PHP script!  >
       	<?php 
       		echo $mid_block; 
       	?>
       	</td>
       	</tr>
    So the whole new table will be in the <IFRAME>.

    Still don't understand why the errors and the PHP script seems to work fine at least there are no errors, and PHP is notorious about showing/producing errors if the code is not right.

    As for running the Script independent from the .HTML file with the button nothing will result as the whole script is "if" dependent on the values passed from the Selected Option.

    Any other clues I should look for?

    DBS4M
    Last edited by dbsupport4me; 10-24-05 at 03:50.

  8. #8
    Join Date
    Feb 2004
    Location
    Irving, TX (Dallas, Fort Worth)
    Posts
    379

    Rechecking Myself

    As for running the Script independent from the .HTML file with the button nothing will result as the whole script is "if" dependent on the values passed from the Selected Option.
    Just to recheck myself ran this in stand alone mode. Been having trouble with my PHP install on the local machine so hosting to test and there I see nothing, no error, no echos, nothing.

    On the local machine it looks like I'm missing a quote mark somewhere but full exam of the code shows nothing.

    DBS4M

  9. #9
    Join Date
    Aug 2004
    Location
    San Antonio, TX
    Posts
    84
    You can't do any new output using PHP without a complete page refresh. If you want to just change something without reloading the page, you need to use Javascript.

  10. #10
    Join Date
    Feb 2004
    Location
    Irving, TX (Dallas, Fort Worth)
    Posts
    379

    Yes

    Quote Originally Posted by ranbla
    You can't do any new output using PHP without a complete page refresh. If you want to just change something without reloading the page, you need to use Javascript.
    Yes an Cache Flushing also

    DBS4M

  11. #11
    Join Date
    Feb 2004
    Location
    Irving, TX (Dallas, Fort Worth)
    Posts
    379

    Found

    Quote Originally Posted by ranbla
    You can't do any new output using PHP without a complete page refresh. If you want to just change something without reloading the page, you need to use Javascript.
    All,

    I found the newt_refresh ( void ) function in the online manual at:

    http://us2.php.net/manual/en/function.newt-refresh.php

    Going to test this to see if it does what I need. I know I cant set action to "self" or derivative thereof. Do you know the correct syntax?

    DBS4M
    Last edited by dbsupport4me; 10-26-05 at 19:29.

  12. #12
    Join Date
    Apr 2005
    Location
    Baltimore, MD
    Posts
    297
    I'm still confused as to what you're trying to do on your web page...

    php is only processed on the web server. Meaning, you can't get any information from php scripts unless you send a request to the server and receive a response. Using strictly php, the code will only execute when the page is generated (ie. when you navigate to the page, refresh, etc.). You can pass information to the page (using forms, etc.) but you can't call a php function from within an html webpage on the client.

    php = server side
    javascript = client side

    Also, the library you found is not for web pages. It is an extension for the RedHat Newt library.
    http://us2.php.net/manual/en/ref.newt.php

  13. #13
    Join Date
    Feb 2004
    Location
    Irving, TX (Dallas, Fort Worth)
    Posts
    379
    Quote Originally Posted by jfulton
    I'm still confused as to what you're trying to do on your web page...

    php is only processed on the web server. Meaning, you can't get any information from php scripts unless you send a request to the server and receive a response. Using strictly php, the code will only execute when the page is generated (ie. when you navigate to the page, refresh, etc.). You can pass information to the page (using forms, etc.) but you can't call a php function from within an html webpage on the client.

    php = server side
    javascript = client side

    Also, the library you found is not for web pages. It is an extension for the RedHat Newt library.
    http://us2.php.net/manual/en/ref.newt.php
    JFulton,

    Thanks for the Server vs. Client explaination. I do want to send to the sever to evaluate variables only and then refresh on the screen. Is that out of the scope of PHP?

    All I need to do is show a different <IFRAME>, within my existing web page, based on the variable values set. Do I have to do this client side with Java?

    DBS4M

  14. #14
    Join Date
    Apr 2005
    Location
    Baltimore, MD
    Posts
    297
    If you want to send something to a php script without refreshing the whole page, just a part of it, you will need to use the javascript XMLHttpRequest Object (ie. AJAX -- see links below).
    Otherwise you can do it just by passing the variables to the script via POST or GET methods, which will refresh the whole page.

    IFRAME question:
    http://www.dbforums.com/t1200326.html

    AJAX:
    http://en.wikipedia.org/wiki/AJAX
    http://www.dbforums.com/t1198717.html
    http://www.webpasties.com/xmlHttpRequest/

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •