WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDES  |  PHP CLASSES  |  CODE SEARCH  |  ARTICLES SEARCH  |  PHP FORUMS  |  PHP MANUAL  |  PHP FUNCTIONS LIST  |  WEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Submit Your Code
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
WeberDev's Monthly code contest PHP Code Contest
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Index
PHP Web Logs (BLogs)
Web Development Resources
Web Development Content
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder
Submit Site
Forex Trading Online forex trading platform

Go Back Add a Comment Send this example to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
BACK ADD A COMMENT SEND TO A FRIEND ADD TO MY FAVORITES ADD CODE EXAMPLES PRINT
Title : Newbie Notes #1 - Making a form return to itself
Categories : PHP, Beginner Guides, HTML and PHP Click here to Update Your Picture
Simon Booth
Date : Apr 21st 2004
Grade : 3 of 5 (graded 4 times)
Viewed : 8737
File : No file for this code example.
Images : No Images for this code example.
Search : More code by Simon Booth
Action : Grade This Code Example
Tools : My Examples List

  Submit your own code examples 
 

NewbieNotes is a little series of tips for people who are new to PHP to give them a few handy tips that the more experienced of us use often

Tip #1

The global variable $PHP_SELF holds the name of the script that's currently running.

You'll often define a form as something like...

<form action="index.php" method="post">


This is usually because you want to check that what the user just entered was valid, to allow for repeated operations until you opt out etc. You'll end up doing it quite a bit.

All very good and proper, but what happens if you rename the file? It's quite easy to forget to remember to update the internal links to your own page?

If you re-write the above as...

<form action="<?php echo $GLOBALS["PHP_SELF"]; ?>" method="post">


PHP will replace the $GLOBALS["PHP_SELF"] with the page you're on. Rename the page and it still works.



Form Submission Using Array's
Categories : PHP, HTML and PHP, Beginner Guides, Arrays
Simple PHP Form Field Generator
Categories : PHP, Beginner Guides, Form Processing, HTML and PHP
How to preset a text string in a textarea input field
Categories : HTML, HTML and PHP, PHP, Beginner Guides
Kewl Date Example
Categories : PHP, HTML and PHP, Date Time, CSS, Beginner Guides
mySQL/PHP/search with multientry form and table output with colored rows
Categories : PHP, Beginner Guides, MySQL, HTML and PHP, Databases
Multiple Select box, Select multiple Items from Menu.List box
Categories : PHP, HTML and PHP, Beginner Guides
PHP3: Formmail. Just a cgi formmail, but than in PHP. It is easy to use!
Categories : HTML and PHP, Email, PHP, Perl, HTML and PHP
Real simple example of removing HTML tags from text then changing \n (new line) to <br>. Could be used in a forum for instance.
Categories : HTML, PHP, HTML and PHP, Beginner Guides
Newbie Notes #9 - Hyperlinking a post
Categories : PHP, Java Script, HTML and PHP, Beginner Guides
Cut your MySQL Connections to 1 line of code
Categories : PHP, Beginner Guides, Databases, MySQL
A simple class with some HTML output functions that would come in handy for consistent page layout etc.
Categories : PHP, PHP Classes, HTML and PHP, HTML, Navigation
a function that builds an HTML select list from any mysql table.
Categories : PHP, MySQL, HTML and PHP
Basic Authentication with sessions
Categories : PHP, Beginner Guides, Authentication, Form Processing, Sessions
Message of the Day - Random Message (Needs MySQL!)
Categories : Databases, HTML and PHP, PHP, MySQL
Check parameters validity. Paranoia was designed to check the validity of the parameters that a php page will receive after a form submission. It can be used to check the variables sent by POST or GET
Categories : Algorithms, HTML and PHP, PHP, Variables
 Shiraz Esat wrote : 1075
It is also possible to have &lt;form action="" ...&gt;
to post back to the page you`re on (no PHP required!).
I`m not sure, though, which browsers support this shortcut.
 
 Ade Morgan wrote : 1076
I don`t think you even need the `action` attribute to post to the same page, all you need is:
&lt;form method="post"&gt;
 
 Boaz Yahav wrote : 1077
The question is : will it work for all clients?
 
 Simon Booth wrote : 1078
Actually the point is that you _should_ use attributes even if they`re optional. It`s good style and if there are any quirks with a browser you`re guaranteed your code will work.

For example you don`t _need_ a closing &lt;/option&gt; tag in a select list but it`s better to have one than not to have one.

The other thing is that you can`t guarantee how JavaScript will work if an attribute is missing and it`s often desirable to alter the value of a given attribute.

Omitting an attribute just cos it works is just lazy.
 
 ezone ezone wrote : 1079
Don`t forget to produce well formated code... it pays in the future :-)
 
 Simon Booth wrote :1080
The above comment is extremely true

Indentation of things like forms etc is also a very good idea - it makes it much easier to find the buit you wanna change if you ever need to do so

The other thing, although we all hate it, is comments. You come back to a bit of code a year from now and suddenly realise you haven`t got the foggiest idea what it did, why id did it, what the parameters are meant to be or what it was meant to return

Never assume you won`t have to modify something later

It`s very useful to build up a little library of functions you use a lot - we get to this later in the series (when Boaz lets you see them all &lt;g&gt;)

If anyone has things they thing I should include in Newbie Notes drop me a line - I`m covering quite a wide range of things with the first 10 to see what people wanna read.