Jump to content
xisto Community
shadow skazi

Php For Beginners By Skazi

Recommended Posts

In creating a php file, you can combine HTML and PHP in one file, but you MUST save it as a .php file if it contains any PHP information. Remember, these tutorials are just for your learning and you should not just copy and paste these into notepad and call it good. You also may realize PHP is alot like the C++ programming language ;)

<html> <head>  <title>PHP Test</title> </head> <body> <?php echo '<p>Hello World</p>'; ?></body></html>

What the <?php echo '<p>Hello World</p>'; ?> command does is it exports The information between the 's as raw text. So it would display as

<p>Hello World</p>

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Now we will use the echo() command to display what browser the viewer is using, so we can put a big fat banner telling them to switch to Mozilla Firefox :P but we don't want to do that because the site would look icky. We don't want to lose traffic, do we?

<?php echo $_SERVER['HTTP_USER_AGENT']; ?>

An output of this code would be Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1) if the user is using Mozilla. What this code does is it gets the broswer information and echos it (displays it) for the viewer.

Now we could use this to our advantage and tell them which browser they are using or if they are not using Mozilla Firefox with this code...

<?phpif (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== FALSE) {?><p>You are using Internet Explorer</p><?php} else {?><p>You are not using Internet Explorer</p><?php}?>

The output would be

<p>You are using Internet Explorer</p> or <p>You are not using Internet Explorer</p>

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

For this one, you will need two PHP files, one for the action, and one for the HTML.

<form action="action.php" method="post"> <p>Your name: <input type="text" name="name" /></p> <p>Your age: <input type="text" name="age" /></p> <p><input type="submit" /></p></form>

That's just simple HTML you would put on a site for a form. You would fill this out and it would display a sentence of "Hi ______, you are __ years old." And this is what we're going to do now. Create a action.php file and put this in it....

Hi <?php echo $_POST['name']; ?>,You are <?php echo $_POST['age']; ?> years old.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

And that concludes the noob tutorial for PHP. I hope this has helped you create great websites as it has helped me get hosting credits >_>

++++++++++++++++
Tutorials Copyright
2005 shadow skazi
++++++++++++++++

Share this post


Link to post
Share on other sites

Hey, if any of you guys need a mail newsletter script, let me know. I got one that works beautifully and is barely a hassle. Only 3 files needed! ;)

Share this post


Link to post
Share on other sites

You don't need to have two pages for a form. You could just have some HTML then PHP then finish the HTML (pretend the file is called "file.php"):

<HTML><HEAD><TITLE>Title</TITLE><BODY><FORM METHOD="POST" ACTION="file.php">Name: <INPUT TYPE="text" NAME="name"><INPUT TYPE="submit"></FORM><?phpecho "Hello, " . $_POST['name'];?></BODY></HTML>

Share this post


Link to post
Share on other sites

thanks...... Although it seems like every PHP tutorial online is all the same........Hello World, they show u how to get your browser and stuff blah blah......... I wish someone would write a tutorial Step by step telling how to do a certain task, and why they did it. I see too many tutorials that just tell u what to do not why you do it. Seems kinda pointless if you aren't sure why your doing something.

Share this post


Link to post
Share on other sites

You all gotta understand that just like math, there is many many different ways to code and use php. There is always another way to do things. For instace the echo function can also be replaced the the print function because they do the exact same thing. Also if you are trying to get an enviornment like HTTP_USER_AGENT or REMOTE_ADDR you can do it by either the $_SERVER variable or the getenv(''); function. See what I mean. So if your trying to correct someone , chances are that there PHP is right and your just showing them another way to do the same thing. Get my point. Well I hope so, lol. :D:D

Share this post


Link to post
Share on other sites

You don't need to have two pages for a form. You could just have some HTML then PHP then finish the HTML (pretend the file is called "file.php"):

 

<HTML><HEAD><TITLE>Title</TITLE><BODY><FORM METHOD="POST" ACTION="file.php">Name: <INPUT TYPE="text" NAME="name"><INPUT TYPE="submit"></FORM><?phpecho "Hello, " . $_POST['name'];?></BODY></HTML>

54199[/snapback]

im just into installin php im not into makin php stuff but soon i will

Share this post


Link to post
Share on other sites

THIS IS EXCELLTENT FOR N00BS.....I personally aint a n0b at php but this post is amazing. You could have added mor einfo as its like not very self explaining and some of the points of basic php hasnt been covered like how to make a simple script for a certain run program. BTW php is a way of running different things....its like html but html can only concentrate on one site while php has a bit more logic and hence it works out things and runs more websites.......Php...well u have to learn html b4 u learn php as it is super hard.... :angry:

Share this post


Link to post
Share on other sites

only way to learn php, is to understand atleast the basic of how coding works, not the basics of php but of coding, like understanding arrays, loops, for, if and other statements as well. Understanding variables, and before you get into php, learn to code html by hand.

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

×
×
  • 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.