WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDESPHP CLASSESCODE SEARCHARTICLES SEARCHPHP FORUMSPHP MANUALPHP FUNCTIONS LISTWEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Join us on FaceBook
Submit a code Example / Snippet Submit Your Code
Poker Tournaments Poker Tournaments
Poker Guide for Developers Poker Guide for Developers
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
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 Resources
Web Development Content
Internet Security Software
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
פרייסז - הכח לקנות עובר לידיים שלך
Texas Holdem Poker Evangelists

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 5 times)
Viewed : 15266
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  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.



Multiple Select box, Select multiple Items from Menu.List box
Categories : PHP, HTML and PHP, Beginner Guides
mySQL/PHP/search with multientry form and table output with colored rows
Categories : PHP, Beginner Guides, MySQL, HTML and PHP, Databases
Form Submission Using Array's
Categories : PHP, HTML and PHP, Beginner Guides, Arrays
How to Create a Shoutbox Using PHP & MySQL
Categories : PHP, MySQL, Web Applications, Beginner Guides, HTML and PHP
Kewl Date Example
Categories : PHP, HTML and PHP, Date Time, CSS, Beginner Guides
Simple PHP Form Field Generator
Categories : PHP, Beginner Guides, Form Processing, HTML and PHP
PHP based HTML rabbing Tools
Categories : PHP, HTML and PHP, Tag Extractors, Regexps, Beginner Guides
Using PHP im HTML image tags
Categories : PHP, HTML and PHP, Graphics, Beginner Guides
Newbie Notes #9 - Hyperlinking a post
Categories : PHP, Java Script, HTML and PHP, Beginner Guides
How to preset a text string in a textarea input field
Categories : HTML, HTML and PHP, 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
OverEasy - PHP generated JavaScript to do mouseovers on your pages. Modify one file and one function does it all for you!
Categories : PHP, Java Script, HTML and PHP, MySQL
Using Postgres and PHP3 Authentication from a Web application
Categories : PostgreSQL, HTML and PHP, Authentication, PHP
The Nearly Perfect Contact Us Form
Categories : PHP, Form Processing, HTML and PHP
 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.