Jump to content
xisto Community
Sign in to follow this  
ppj

Php Tutorial - Basics...up To Mysql/file Commands

Recommended Posts

the best way to start php is probably not adjusting a script IMO - that misses out a stage. - the very first stage - here... Why use php? because it allows things to be generated very quickly - without lots of html pages. It enables users you choose to allow, to input their own content to the pages you want them to. 1) save these files as anyfilename.php - pick your names, upload them to a php enabled server and go to the url they are at... 2) understand <?, ?>, .php, //////, /* */, and ; Code: <? ?> THis tells the web browser when to expect php coding. So... when writing php, this needs to encase all php code - or it will be formatted as html. Naming a filename .php allows for <? and ?> to be expected - or it will show as html. Code: <? //// hello - this line will be overlooked /* hello these lines will be overlooked*/ ?> both of these 'hello's' will not be formatted as php - these 2 bits of code exclude the contained text. Code: <? print "hello" ?> print tells the php to print the contained text - if a variable is used then ""'s are not usually needed, if "" are used then the content will be shown as html. The above WILL NOT WORK. Each line of php code needs to be ended with a ;. 3) printing basic html Code: <? print 'hello world'; ?> open the file - it will show the words hello world with no formatting. 4) printing and setting variables Code: <? $hello = 'hello world'; ///setting variables print $hello; ///printing variables ?> 5) if else with variables Code: <? $a = $_GET['a']; ///setting variables (3) if (isset($a)) { print '<a href="?a=0">Click here</a><br>'; ///printing html (2) print "a is set to:".$a; } else { print '<a href="?a=1">Click here</a><br>'; ///printing html (2) print "a is empty"; } ?> for a form... adjusting my last script from above... 6) create the form html - save as form.php. Code: <? $form = <<<HTML <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>Form!</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <body> <form action="?a=1" method="post" name="" id=""> <table width="50%" border="0" align="center" cellpadding="4" cellspacing="0"> <tr> <td width="22%">Subject</td> <td width="78%"><input name="value" type="text" id="value"></td> </tr> </table> </form> </body> </html> <br> HTML; ?> that basically mates a text box to enter something into - which posts to ?a=1 then save the following as anythingyouwant.php .... load it...and should work as a simple form. Code: <? include 'form.php'; ///include the form we just made - so that you can print it when you need to. $a = $_GET['a']; ///setting variables - has the script been submitted yet? - get the value from the url if (isset($a)) { ///the script has been submitted $value = $_POST['value']; ///retrieve the posted data. print '<a href="/?">Click here</a><br>'; ///printing html - return to script not submitted print "value is set to:".$value; } else { ////form isnt submitted - so print it. print "a is empty<br>"; print "therefore include the form<br><br>"; ///printing html (2) print $form; } ?> should work... unless i missed off a ; or something silly (let me know below...if i have) if you want to check the field to make it required - and show a form with a message if its not filled in, then this would be the edited version..... Code: <? include 'form.php'; ///include the form - so that you can print it when you need to. $a = $_GET['a']; ///setting variables - has the script been submitted yet? if (isset($a)) { ///the script has been submitted $value = $_POST['value']; ///retrieve the posted data. if(isset($value)) { /////////FIELD SET?//////////// print '<a href="/?">Click here</a><br>'; ///printing html - return to script not submitted print "value is set to:".$value; } else { //////FEILD NOT SET - show form again, with message to fill it out/////// print "The required fields are empty<br>"; print "therefore include the form<br><br>"; ///printing html (2) print $form; } } else { ////form isnt submitted - so print it. print "a is empty<br>"; print "therefore include the form<br><br>"; ///printing html (2) print $form; } ?> then learn mysql and your sorted

Share this post


Link to post
Share on other sites

I have been looking for an ez to use PHP tutorial and finally i found one. I kinda have an understanding about PHP from playing around with scripts and modifiying them but i dont know all the rules and tags yet. Im sure this tutorial will help me improve my coding skills greatly (Im not saying im a pro by all means tho hehe) Thanx for taking the time to post it.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.