IPB

Welcome Guest ( Log In | Register )



Tags
This content has not been tagged yet
2 Pages V   1 2 >  
Reply to this topicStart new topic

Php For Beginners

, By Skazi

shadow skazi
no avatar
Member [Level 3]
******
Group: Members
Posts: 91
Joined: 20-December 04
Member No.: 2,823



Post #1 post Feb 24 2005, 09:20 PM
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
no avatar
Privileged Member
*********
Group: Members
Posts: 661
Joined: 10-January 05
Member No.: 3,189



Post #2 post Feb 25 2005, 02:07 AM
nice little tutorial. tongue.gif
Go to the top of the page
+Quote Post
ill
no avatar
Super Member
*********
Group: Members
Posts: 385
Joined: 10-August 04
From: United States
Member No.: 761



Post #3 post Feb 25 2005, 02:45 AM
Simple, and great for people who wanna start with PHP. Good job!
Go to the top of the page
+Quote Post
Amezis
no avatar
Privileged Member
*********
Group: Members
Posts: 535
Joined: 14-February 05
From: Oslo, Norway
Member No.: 3,759



Post #4 post Feb 25 2005, 10:22 AM
Nice tutorial, and I really need to learn how to use php...
Go to the top of the page
+Quote Post
egbakaet
no avatar
Newbie [Level 1]
*
Group: Members
Posts: 15
Joined: 25-February 05
From: Somewhere? LOL.
Member No.: 3,988



Post #5 post Feb 25 2005, 10:54 PM
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
no avatar
Super Member
*********
Group: Members
Posts: 421
Joined: 17-January 05
From: Somewhere over the rainbow
Member No.: 3,317



Post #6 post Feb 25 2005, 11:03 PM
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
no avatar
Super Member
*********
Group: Members
Posts: 209
Joined: 9-October 04
Member No.: 1,574



Post #7 post Feb 25 2005, 11:47 PM
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
no avatar
Privileged Member
*********
Group: Members
Posts: 629
Joined: 26-February 05
Member No.: 3,995



Post #8 post Feb 26 2005, 04:01 AM
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
no avatar
Member [Level 1]
****
Group: Members
Posts: 55
Joined: 26-February 05
Member No.: 3,996



Post #9 post Feb 26 2005, 05:17 AM
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.
Go to the top of the page
+Quote Post
Seņor Maniac
no avatar
Super Member
*********
Group: Members
Posts: 272
Joined: 10-September 04
From: (>0_0)>oooO Hadoken
Member No.: 1,068



Post #10 post Feb 26 2005, 05:28 AM
taken from php.net
Go to the top of the page
+Quote Post

2 Pages V   1 2 >
Reply to this topicStart new topic

Collapse

> Similar Topics

    Topic Title Replies Topic Starter Views Last Action
No New Posts 2 Nico Robin 298 25th June 2008 - 03:17 PM
Last post by: Nico Robin
No New Posts   2 Saint_Michael 1,470 10th August 2007 - 05:27 PM
Last post by: kevlar557
No New Posts 5 karlo 612 2nd March 2005 - 02:34 PM
Last post by: karlo
No New Posts   2 Wideawake 690 29th June 2006 - 05:24 AM
Last post by: Wideawake
No New Posts   3 AllfatherBlack 380 22nd January 2006 - 06:41 AM
Last post by: melicaster
No New Posts   3 Wideawake 886 30th September 2007 - 12:50 AM
Last post by: Trap FeedBacker
No New Posts 2 Earths Daughter 736 14th March 2006 - 12:33 AM
Last post by: Earths Daughter
No New Posts   1 xor_xor_xor 916 5th June 2006 - 08:36 AM
Last post by: jibnet
No New Posts   12 mama_soap 2,899 14th July 2008 - 06:01 PM
Last post by: serverph
No New Posts   1 .hack//GU 387 20th May 2006 - 06:49 AM
Last post by: Justin S.


 



RSS Lo-Fi Version Time is now: 3rd December 2008 - 08:03 PM