Welcome Guest ( Log In | Register)



2 Pages V   1 2 >  
Reply to this topicStart new topic
> Php For Beginners, By Skazi
shadow skazi
post Feb 24 2005, 09:20 PM
Post #1


Member [Level 3]
******

Group: Members
Posts: 91
Joined: 20-December 04
Member No.: 2,823



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 tongue.gif

CODE
<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

CODE
<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 tongue.gif but we don't want to do that because the site would look icky. We don't want to lose traffic, do we?

CODE
<?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...

CODE
<?php
if (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.

CODE
<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....

CODE
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
++++++++++++++++
Go to the top of the page
 
+Quote Post
whyme
post Feb 25 2005, 02:07 AM
Post #2


Privileged Member
*********

Group: Members
Posts: 661
Joined: 10-January 05
Member No.: 3,189



nice little tutorial. tongue.gif
Go to the top of the page
 
+Quote Post
ill
post Feb 25 2005, 02:45 AM
Post #3


Super Member
*********

Group: Members
Posts: 386
Joined: 10-August 04
From: United States
Member No.: 761



Simple, and great for people who wanna start with PHP. Good job!
Go to the top of the page
 
+Quote Post
Amezis
post Feb 25 2005, 10:22 AM
Post #4


Privileged Member
*********

Group: Members
Posts: 535
Joined: 14-February 05
From: Oslo, Norway
Member No.: 3,759



Nice tutorial, and I really need to learn how to use php...
Go to the top of the page
 
+Quote Post
egbakaet
post Feb 25 2005, 10:54 PM
Post #5


Newbie [Level 1]
*

Group: Members
Posts: 15
Joined: 25-February 05
From: Somewhere? LOL.
Member No.: 3,988



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! biggrin.gif
Go to the top of the page
 
+Quote Post
thebluekirby
post Feb 25 2005, 11:03 PM
Post #6


Super Member
*********

Group: Members
Posts: 421
Joined: 17-January 05
From: Somewhere over the rainbow
Member No.: 3,317



wow... this tuturial can come in handy when I feel like scripting in PHP! thanks!
Go to the top of the page
 
+Quote Post
Ralphie
post Feb 25 2005, 11:47 PM
Post #7


Super Member
*********

Group: Members
Posts: 209
Joined: 9-October 04
Member No.: 1,574



thanks a lot for that tutorial. i am hoping to soon learn php so this is a nice little intro
Go to the top of the page
 
+Quote Post
beeseven
post Feb 26 2005, 04:01 AM
Post #8


Privileged Member
*********

Group: Members
Posts: 629
Joined: 26-February 05
Member No.: 3,995



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"):

CODE

<HTML>
<HEAD>
<TITLE>Title</TITLE>
<BODY>
<FORM METHOD="POST" ACTION="file.php">
Name: <INPUT TYPE="text" NAME="name">
<INPUT TYPE="submit">
</FORM>
<?php
echo "Hello, " . $_POST['name'];
?>
</BODY>
</HTML>
Go to the top of the page
 
+Quote Post
NotoriousZach
post Feb 26 2005, 05:17 AM
Post #9


Member [Level 1]
****

Group: Members
Posts: 55
Joined: 26-February 05
Member No.: 3,996



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.