The ProgrammersTalk Community
Forum Register Search Today's Posts Mark Forums Read
Register

Go Back   The ProgrammersTalk Community > Web Programming > PHP


Welcome to the The ProgrammersTalk Community forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact us.
Tags: , ,

Reply
 
LinkBack (4) Thread Tools    Display Modes   
  4 links from elsewhere to this Post. Click to view. #1 (permalink)  
Old 06-13-2007, 11:49 AM
HelloWorld's Avatar
HelloWorld HelloWorld is offline
Programming Expert
Awards Showcase
Quality Tutorial 
Total Awards: 1
Join Date: Jun 2007
Location: In front of computer...
Posts: 1,111
iTrader: (0)
HelloWorld will become famous soon enoughHelloWorld will become famous soon enoughHelloWorld will become famous soon enough
Icon9 How do you get started with PHP?

I've had programming background, but sometimes I'm just confused on where should I start? I've understood some conscept of PHP, but I'm just not sure on how does it work on web application. For example, I want to create a login page:

HTML Code:
<form> <input type="text" id="username"></input> <input type="submit" id="password"></input> </form>
And then, where do you call PHP? I'm sure that it's not like JavaScript right? where you can call it from external, or indented within HEAD tag? How can I process the information based on the ID with PHP? thanx

__________________

Digg this Post! Del.Icio.Us this Post! Technorati this Post! Furl this Post! Mister Wong this Post! Newsvine this Post! Spurl this Post! Reddit this Post! Netscape this Post!
Reply With Quote
  #2 (permalink)  
Old 06-13-2007, 11:55 AM
Lee's Avatar
Lee Lee is offline
PT Staff*
Awards Showcase
Quality Tutorial 
Total Awards: 1
Join Date: Jun 2007
Location: Blackpool, UK
Posts: 616
iTrader: (0)
Lee will become famous soon enoughLee will become famous soon enoughLee will become famous soon enoughLee will become famous soon enough
Quote:
Originally Posted by HelloWorld View Post
I've had programming background, but sometimes I'm just confused on where should I start? I've understood some conscept of PHP, but I'm just not sure on how does it work on web application. For example, I want to create a login page:

HTML Code:
<form> <input type="text" id="username"></input> <input type="submit" id="password"></input> </form>
And then, where do you call PHP? I'm sure that it's not like JavaScript right? where you can call it from external, or indented within HEAD tag? How can I process the information based on the ID with PHP? thanx
You could start <form action="handlingform.php"> at the start then it would carry out the instructions in that php file, at the moment i prefer this.

The other way is if you have a php page with the form on you can do:

PHP Code:
<?php

If (isset($_GET['password'])){ //password is name of submit button, thats why we use that.
//do statements like add to db here

} else {

echo 
"table code"// here echo your table
}
(i dont use id="" all that much, i use name="")
i hope i have done this correctly and that it helps.

__________________

Digg this Post! Del.Icio.Us this Post! Technorati this Post! Furl this Post! Mister Wong this Post! Newsvine this Post! Spurl this Post! Reddit this Post! Netscape this Post!
Reply With Quote
  #3 (permalink)  
Old 06-13-2007, 11:59 AM
HelloWorld's Avatar
HelloWorld HelloWorld is offline
Programming Expert
Awards Showcase
Quality Tutorial 
Total Awards: 1
Join Date: Jun 2007
Location: In front of computer...
Posts: 1,111
iTrader: (0)
HelloWorld will become famous soon enoughHelloWorld will become famous soon enoughHelloWorld will become famous soon enough
Quote:
You could start <form action="handlingform.php"> at the start then it would carry out the instructions in that php file, at the moment i prefer this.
Can't we just add that to display the login form? Because at the beginning, submit button is not pressed right, so shouldn't it display what's within the else statement?

__________________

Digg this Post! Del.Icio.Us this Post! Technorati this Post! Furl this Post! Mister Wong this Post! Newsvine this Post! Spurl this Post! Reddit this Post! Netscape this Post!
Reply With Quote
  #4 (permalink)  
Old 06-13-2007, 12:06 PM
Lee's Avatar
Lee Lee is offline
PT Staff*
Awards Showcase
Quality Tutorial 
Total Awards: 1
Join Date: Jun 2007
Location: Blackpool, UK
Posts: 616
iTrader: (0)
Lee will become famous soon enoughLee will become famous soon enoughLee will become famous soon enoughLee will become famous soon enough
Im not sure you get what i mean, you have a html page, say login.htm and that contains your form:

<form action="handlefile.php">
<input type="text" id="username">
</input>
<input type="submit" id="password">
</input>
</form>

then you have that other file handlefile.php, you see in the above when the button is clicked it will then carry out what is in the php file.

__________________

Digg this Post! Del.Icio.Us this Post! Technorati this Post! Furl this Post! Mister Wong this Post! Newsvine this Post! Spurl this Post! Reddit this Post! Netscape this Post!
Reply With Quote
  #5 (permalink)  
Old 06-13-2007, 12:21 PM
TeraTask's Avatar
TeraTask TeraTask is offline
PT Staff*
Awards Showcase
Quality Tutorial Quality Tutorial Quality Tutorial 
Total Awards: 3
Join Date: Jun 2007
Location: Reno, NV
Posts: 430
iTrader: (0)
TeraTask will become famous soon enoughTeraTask will become famous soon enoughTeraTask will become famous soon enoughTeraTask will become famous soon enoughTeraTask will become famous soon enoughTeraTask will become famous soon enough
Quote:
Originally Posted by Lee View Post
(i dont use id="" all that much, i use name="")
id is important to use if you want to use a scripting language like javascript to access information on the page through the DOM. name is important to use for submitting data as the value of name will be the new variable on the server when the form is submittted.

Now, let's look at

Code:
<form action="handlefile.php"> 
<input type="text" id="username">
</input>
<input type="submit" id="password">
</input> 
</form>
First, rewrite it as
Code:
<form action="login.php" method="post"> 
<input type="text" id="username" name="username" /><br />
<input type="password" id="password" name="password" /><br />
<input type="submit" value="Login" />
</form>
Then, assuming that form is also on login.php, you can access the username and password through $_POST['username'] and $_POST['password'], respectively. Here's an example.


PHP Code:
<?php
if (strlen($_POST['username']) > && strlen($_POST['password']) > 0) {
  
// verify username and password
 
if ($_POST['username'] == "allowed_username" && $_POST['password'] == "password") {
  
//Take login action
  
} else {
   
//Take invalid login action
  
}
}
?>
 <form action="login.php" method="post"> 
 <input type="text" id="username" name="username" /><br />
 <input type="password" id="password" name="password" /><br />
<input type="submit" value="Login" />
 </form>

__________________
Jeremy Miller
Content Farmer - Optimized Automated Blog Posting

Digg this Post! Del.Icio.Us this Post! Technorati this Post! Furl this Post! Mister Wong this Post! Newsvine this Post! Spurl this Post! Reddit this Post! Netscape this Post!
Reply With Quote
  #6 (permalink)  
Old 06-13-2007, 12:31 PM
Lee's Avatar
Lee Lee is offline
PT Staff*
Awards Showcase
Quality Tutorial 
Total Awards: 1
Join Date: Jun 2007
Location: Blackpool, UK
Posts: 616
iTrader: (0)
Lee will become famous soon enoughLee will become famous soon enoughLee will become famous soon enoughLee will become famous soon enough
Quote:
Originally Posted by TeraTask View Post
the value of name will be the new variable on the server when the form is submittted.
Yes, using name for that bit works fine for me.

and i thought you needed some help, not making examples

__________________

Digg this Post! Del.Icio.Us this Post! Technorati this Post! Furl this Post! Mister Wong this Post! Newsvine this Post! Spurl this Post! Reddit this Post! Netscape this Post!
Reply With Quote
  #7 (permalink)  
Old 06-13-2007, 12:59 PM
HelloWorld's Avatar
HelloWorld HelloWorld is offline
Programming Expert
Awards Showcase
Quality Tutorial 
Total Awards: 1
Join Date: Jun 2007
Location: In front of computer...
Posts: 1,111
iTrader: (0)
HelloWorld will become famous soon enoughHelloWorld will become famous soon enoughHelloWorld will become famous soon enough
what's the difference between

PHP Code:
strlen 
and

PHP Code:
isset 
when do I want use one over the other?

__________________

Digg this Post! Del.Icio.Us this Post! Technorati this Post! Furl this Post! Mister Wong this Post! Newsvine this Post! Spurl this Post! Reddit this Post! Netscape this Post!
Reply With Quote
  #8 (permalink)  
Old 06-13-2007, 01:09 PM
TeraTask's Avatar
TeraTask TeraTask is offline
PT Staff*
Awards Showcase
Quality Tutorial Quality Tutorial Quality Tutorial 
Total Awards: 3
Join Date: Jun 2007
Location: Reno, NV
Posts: 430
iTrader: (0)
TeraTask will become famous soon enoughTeraTask will become famous soon enoughTeraTask will become famous soon enoughTeraTask will become famous soon enoughTeraTask will become famous soon enoughTeraTask will become famous soon enough
strlen tells the length of the string. isset tells only if the variable has been defined. I don't want to process a login if the variable is set - it could be empty. I only want to process the login if the the user actually entered something, so I check to make sure that the string is not empty.

__________________
Jeremy Miller
Content Farmer - Optimized Automated Blog Posting

Digg this Post! Del.Icio.Us this Post! Technorati this Post! Furl this Post! Mister Wong this Post! Newsvine this Post! Spurl this Post! Reddit this Post! Netscape this Post!
Reply With Quote
  #9 (permalink)  
Old 06-13-2007, 01:11 PM
Lee's Avatar
Lee Lee is offline
PT Staff*
Awards Showcase
Quality Tutorial 
Total Awards: 1
Join Date: Jun 2007
Location: Blackpool, UK
Posts: 616
iTrader: (0)
Lee will become famous soon enoughLee will become famous soon enoughLee will become famous soon enoughLee will become famous soon enough
PHP Code:
strlen() 
Is to check the length of something, you place that something inside the brackets and it will check the length, you can then use that to do what you did
PHP Code:
strlen($_POST['username']) > 
That checks to see if the username is longer than 0 so is it there?
PHP Code:
isset() 
As far as i know its used, for example to see if the button has been clicked like the example i gave.

__________________

Digg this Post! Del.Icio.Us this Post! Technorati this Post! Furl this Post! Mister Wong this Post! Newsvine this Post! Spurl this Post! Reddit this Post! Netscape this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

   Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

LinkBacks (?)
LinkBack to this Thread: http://www.programmerstalk.net/thread712.html
Posted By For Type Date
J!NX Forums - start learning php This thread Refback 06-24-2007 12:35 PM
How do I make required fields in PHP form This thread Refback 06-19-2007 10:34 AM
How do I make required fields in PHP form This thread Refback 06-17-2007 04:59 PM
Do an action based on input value? This thread Refback 06-13-2007 03:36 PM


All times are GMT -7. The time now is 08:03 PM. Powered by vBulletin
Copyright © 2000 - 2007, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO © 2007 ProgrammersTalk Sedo - Buy and Sell Domain Names and Websites project info: programmerstalk.net Statistics for project programmerstalk.net etracker® web controlling instead of log file analysis


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50