looking for study partner/s to learn PHP!

First Assignment:

Create a form that allows someone to enter their name, and then have PHP check to see if the name variable is null or not. If it is empty, then tell them to enter their name, if it is not empty, print "Hello {name}" on the screen.

There you go. Have fun.

Done!

http://electrohousedownloads.com/learn-php/greyhat/ex1.php

Code:
<html>
<body>
<?php
if($_POST['name'] == NULL){
  echo "<form action=\"ex1.php\" method=\"post\"/>
  Please enter your name <input type=\"text\" name=\"name\"/>
  <br>
  <input type=\"submit\" value=\"Submit\"/>
  </form>";
}else{
  $name=$_POST['name'];
  echo "Hello $name , i can make PHP powered forms!";
}
?>
</body>
</html>
Any comments?
Thanks.
 


you did well greyhat, but were you afraid to remove the space between $name and , comma ? lol. It's completely legal code.
 
Links

A few links.
W3schools - online reference and tutorials. When searching for an answer etc.. ad w3 in to the query and this site usually pops up with the solution.
PHP Tutorial

php.net - the official php website. Documentation, reference, resources etc... i have seen this referenced many times but im still trying to figure out what do with it! (anybody?) I heard that people go on there, get code and hack apps together but am yet to try this.
PHP: Hypertext Preprocessor

Forums to join
Devshed forums - busy webmaster/developer forum with php section.
Dev Shed Forums - Open Source web development
codewalkers.com - dedicated php / mysql forum, part of the devshed family.
PHP Help, PHP Code - Codewalkers.com
Phpfreaks - another busy dedicated php forum. People on here are always helpful.
PHP Freaks - Index
webdeveloper.internet.com - another busy web dev forum with php section.
WebDeveloper.com

I would reccomend signing up to at least a few of these forums. When you get stuck just post your question to all the forums and 9 times out of 10 you will get an answer. Remember - these websites are not wickedfire so that means NO DICKROLLS or swearing OR boobs!! Same applies, be courteous and ask qality questions for best results. Try and give something back if you can.

Random hacking link - why not?!
Google tutorial lets developers play malicious hacker ? The Register
Enjoy!
 
Anybody started the book yet? I have read the first chapter and i'm really impressed, it is much more engaging than any of the others i have read. I will be posting my answers to chapter 1 soon.
 
I've read the first chapter and am attempting to do the problem above now. I'm working on Wordpress so I'm gona have to readup on how WP uses PHP functions. I'm pretty confused right now.

What is the significance of "action"? Also what is the difference between creating a new .php file or simply defining a new php function like function hello_form() {} ?
 
I'm having problems. I defined function hello_form() like so

function hello_form(){
if(!isset($_POST['form_posted'])) {
$self=$_SERVER['PHP_SELF'];
echo "<form method=\"post\" action=\"$self\"/>
Enter your name <input type=\"text\" name=\"name\"/>
<input type=\"hidden\" name=\"form_posted\"/>
<br>
<input type=\"submit\" value=\"Submit\"/>
</form>";

} else {

$name=$_POST['name'];

echo "How much money you make today, $name?";


}
}

(yes I stole some of your code but im just trying to figure out WP right now)
It comes out like this but when I click submit it gives me a 404
PHP Tests | Supplement Free
(ignore the rest of the site i had no other suitable domain up)

I imagine the problem has to do with $_SERVER, i dont really understand that and action.
 
I've read the first chapter and am attempting to do the problem above now. I'm working on Wordpress so I'm gona have to readup on how WP uses PHP functions. I'm pretty confused right now.

What is the significance of "action"? Also what is the difference between creating a new .php file or simply defining a new php function like function hello_form() {} ?

If you are having troubles then just start with the book or i wont be able to help. I am in this for the long haul and i reckon we can have the book done in a few weeks. Then we will move on and apply our new found skills to wordpress.
 
What is the significance of "action"? Also what is the difference between creating a new .php file or simply defining a new php function like function hello_form() {} ?

<form action="script.php" method="post">

The action attribute specifies which php script to pass the form data to. Not sure what you mean by the other question... You could have your whole app in one page if you wanted but it would be complicated. you split it up for clarity/maintainabilty etc...
 
* boobs for getting to page 2!!

ROSIE-JONES-NATALIE-BLAIR-FRONT-MAGAZINE1.jpg
 
I'm having problems. I defined function hello_form() like so

function hello_form(){
if(!isset($_POST['form_posted'])) {
$self=$_SERVER['PHP_SELF'];
echo "<form method=\"post\" action=\"$self\"/>
Enter your name <input type=\"text\" name=\"name\"/>
<input type=\"hidden\" name=\"form_posted\"/>
<br>
<input type=\"submit\" value=\"Submit\"/>
</form>";

} else {

$name=$_POST['name'];

echo "How much money you make today, $name?";


}
}

Always look at your output:
<form name="helloform" action="" method="post"/>
Notice something missing?

::emp::
 
For those that learn better visually the Lynda.com training tutorials are solid. Im finishing the first one tonight, and my strategy has been to go through them all, play around a bit, and then ill go to the book once they are done. Ill pull whatever I can from memory and reteach myself the rest from the text.
 
if you're refering to action being empty, its apparently suppose to be for wordpress because of dynamic urls, otherwise i have no clue what its suppose to be.

As said before

Code:
<form [B][COLOR=Red]action[/COLOR][/B]="script.php"  method="post">

The action attribute specifies which php script to pass the form data  to. Not sure what you mean by the other question... You could have your  whole app in one page if you wanted but it would be complicated. you  split it up for clarity/maintainabilty etc...

I would also recommend setting up somewhere outside of WP where you can play around with PHP.

::emp::
 
Chapter one - answer

Finally got it done. It was pretty easy but just been busy. Anyway, it is a form that gathers data. displays it back and emails it to me. This is the answer for the text book. I am going to spice things up a bit. I will try and use the null value from SEO MIKES's task to check on each input and maybe display an error message. But that might take a while! First i am going to add a captcha and add the option to send a copy to the user. So watch this space. Please have a look and try it out whatever. it will be better with my mods.

BE WARNED! - if you are using WAMP on windows the mail() function needs configuring before it will work.

Aliens Abducted Me - Report an Abduction

Code:
<html>
<head>
<title>Aliens Abducted Me - Report an Abduction</title>
<link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body>
<h2>Aliens Abducted Me - Report an Abduction</h2>
<?php
 
// script varaibles
$first_name = $_POST['firstname'];
$last_name = $_POST['lastname'];
$email = $_POST['email'];
$when_it_happened = $_POST['whenithappened'];
$how_long = $_POST['howlong'];
$how_many = $_POST['howmany'];
$alien_description = $_POST['aliendescription'];
$what_they_did = $_POST['whattheydid'];
$fang_spotted = $_POST['fangspotted'];
$other = $_POST['other'];
 
//email variables
$to = 'leedswebsolutions@googlemail.com';
$subject = 'Aliens Abducted Me - Abduction Report';
 
//email message string variable
$msg = "$first_name $last_name was abducted on $when_it_happened and was gone for $how_long\n" .
 "Number of aliens: $how_many\n" .
 "Describe them: $alien_description\n" .
 "What they did: $what_they_did\n" .
 "Was Fang there? $fang_spotted\n" .
 "Other comments: $other\n";
 
//HTML response
echo 'Thanks for submitting the form.<br />';
echo $first_name . ' ' . $last_name .', you were abducted ' . $when_it_happened . ' and gone for ' .  $how_long . '.<br />';
echo 'Number of aliens: ' . $how_many . '.<br />';
echo 'Describe them: ' . $alien_description . '.<br />';
echo 'What they did: ' . $what_they_did . '.<br />';
echo 'Was Fang there? ' . $fang_spotted . '.<br />';
echo 'Other comments: ' . $other . '.<br />';
echo 'Your email address is ' . $email;
 
//send email
mail($to, $subject, $msg, 'From:' . $email);
 
?>
</body>
</html>