Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PHP Newbie please help 1

Status
Not open for further replies.

k4ghg

Technical User
Dec 25, 2001
191
US
Hi - I am new to PHP and need some help modifing a script some one gave me. The Script has a submit button, that takes a name and uses it in a funtion, afterwards it writes a table to screen. My first question is what do I need to put in the form action (i.e., '<form action= method="post">) since I am using a funtion on the page with the submit. When the data is displayed does the new page have a name (i.e., newpage.php) or does it keep the origional pages name. I think I need this information so that the user can change the input name and regenerate the page. Thanks you for any help. Ronnie
 
add the name of the physical page (i.e. page.php) as the action. the page name is always the name of the file on the server. you can, of course, change the page title at will.

if uncertain you could try this:
Code:
<form action="<?=$_SERVER['PHP_SELF']?>" action="post">
this will tell php to insert the current page name into the action field of the form.

hth
Justin
 
Hi Justin - Thanks, I was wondering if you could answer one more (dumb?) question. Should the submit be in or out of the code?
I tried:

<?php
...
echo '<form action="test.php" method="post"><p align="center">Zip Code:<input style="width:60px;" type="text" name="zip" value="' .$zip_code. '" />&nbsp;<input style="width:60px;" type="submit" value="Submit" /></p></form>';
parseStationFeed();
displayLiveDataForStations();
?>

and this;
<form action="test.php" method="post"><p align="center">Zip Code:<input style="width:60px;" type="text" name="zip" value="' .$zip_code. '" />&nbsp;<input style="width:60px;" type="submit" value="Submit" /></p></form>
<?php
...
parseStationFeed();
displayLiveDataForStations();
?>

and had problems with both.

Thanks again...Ronnie
 
Do I need to change any of the permissions (chmod) to use PHP and submit?
 
chmod deals with file permissions. you need concern yourself with this only if you are writing or reading from files within php.

your two code snips are equally acceptable in terms of style. fixed the two would look like:
Code:
<?php
echo <<<contents
<form 	action="test.php" 
		method="post">
<p align="center">
		Zip Code:
		<input 	style="width:60px;" 
				type="text" 
				name="zip" 
				value="$zip_code" />
		&nbsp;
		<input 	style="width:60px;" 
				type="submit" 
				value="Submit" />
</p>
</form>
contents;
   parseStationFeed();
   displayLiveDataForStations();
?>  

<form 	action="test.php" 
		method="post">
<p align="center">
		Zip Code:
		<input 	style="width:60px;" 
				type="text" 
				name="zip" value="<?=$zip_code?>" />
		&nbsp;
		<input 	style="width:60px;" 
				type="submit" 
				value="Submit" />
</p>
</form>
<?php
   parseStationFeed();
   displayLiveDataForStations();
?>

note the first uses the heredoc syntax. i find this easier for crafting long strings of html within php
 
Thanks for all your help...Ronnie
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top