- Joined
- Feb 9, 2005
- Messages
- 2,013
- Reaction score
- 6
I dont really know if any of you are interested in PHP, but here are the basics of learning the echo() statements, else() statements, and variables ($) .
--------------------------------
What is needed for this
tutorial?
--------------------------------
1. PHP 4.3.0 or higher
2. A webserver
--------------------------------
Before beginning to script
--------------------------------
IMPORTANT! Remember to always start with php tags before you start scripting any php scripts.
<? is to open a script, and ?> is to close it.
--------------------------------
What are echo statements?
--------------------------------
echo statements are what prints on the pages.
echo statements are pretty useful when coding forms, login scripts, or basically "all" php scripts.
--------------------------------
Lets get started!
--------------------------------
Make a new, flat php document. I use dreamweaver since it already provides the html codings when i create a new document:
Now between the < body > and < /body > tags, enter something like:
And save it. (I called mine breeze.php).
Now open your browser. Something like
--------------------------------
What are variables?
--------------------------------
Variables are widgets used to temporarily store values.
--------------------------------
Lets get started!
--------------------------------
Sure, variables look hard to do, but its nothing close as hard as doing "else" statements. Variables should be easy once you actually understand what it does.
Create a new php document if you want, (breeze2.php)
Between the body tags, enter like so:
Now save it as a .php (I called mine BreezE.php once again)
And open it up in an Internet Browser.
Here is how it should look like:
You can see that the variables we made were printed out in the echo statements.
Now, wasnt that easy?
Its time to go to a much harder step.. the "else" statements..
--------------------------------
What are else statements?
--------------------------------
Its a bit difficult to explain, but it is a code that executes when something else is either not defined, defined, or was idle.
--------------------------------
Lets get started!
--------------------------------
Ill make a html form so it makes it easier to understand. (Call this breezeform.php if you want.
We can see that where it says action="breeze2.php" goes directly to breeze2.php and executes the php actions in that file.
Make a new php document. (breeze2.php)
And enter in these codes between the body tags:
I pretty much explained what the else statements does in the code box.. where i put the // tags
Also, I have to admit why we need those ** and { tags there, but a lot of people/websites say you need them to work something in your php script.
Here are some screenshots to how this else statements work:
If you chose Female, it would print out: "Good day, Madam!"
Now if you DIDN'T choose a gender and pressed Submit:,
it would print out:
Well.. this is pretty much it for my tutorial Have Fun!
-----------------------------------------------------------------
And when im still in PHP i will post the PHP code for stopping SQL Injection:
Ive seen many ask about it so now here it is
Also post youre ideas, basics or tutorial.
--------------------------------
What is needed for this
tutorial?
--------------------------------
1. PHP 4.3.0 or higher
2. A webserver
--------------------------------
Before beginning to script
--------------------------------
IMPORTANT! Remember to always start with php tags before you start scripting any php scripts.
<? is to open a script, and ?> is to close it.
--------------------------------
What are echo statements?
--------------------------------
echo statements are what prints on the pages.
echo statements are pretty useful when coding forms, login scripts, or basically "all" php scripts.
--------------------------------
Lets get started!
--------------------------------
Make a new, flat php document. I use dreamweaver since it already provides the html codings when i create a new document:
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
</head>
<body>
</body>
</html>
Now between the < body > and < /body > tags, enter something like:
Code:
<?
echo "BreezE is the best";
?>
And save it. (I called mine breeze.php).
Now open your browser. Something like
You must be registered to see links
and you can see that the echo statements we just did just printed out like so:
You must be registered to see links
--------------------------------
What are variables?
--------------------------------
Variables are widgets used to temporarily store values.
--------------------------------
Lets get started!
--------------------------------
Sure, variables look hard to do, but its nothing close as hard as doing "else" statements. Variables should be easy once you actually understand what it does.
Create a new php document if you want, (breeze2.php)
Between the body tags, enter like so:
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
</head>
<body>
<?
// Create the variables
$name = 'BreezE';
$date = '4/3/05';
$hobbies = 'PHP Scripting';
$book = 'Go Ask Alice';
$d2server = 'Rebornz';
// Print the values
echo "$name has read the book called $book in $date. He actually said it reminded him of a Diablo II server called $d2server. His hobbies are $hobbies.";
?>
</body>
</html>
Now save it as a .php (I called mine BreezE.php once again)
And open it up in an Internet Browser.
Here is how it should look like:
You must be registered to see links
You can see that the variables we made were printed out in the echo statements.
Now, wasnt that easy?
Its time to go to a much harder step.. the "else" statements..
--------------------------------
What are else statements?
--------------------------------
Its a bit difficult to explain, but it is a code that executes when something else is either not defined, defined, or was idle.
--------------------------------
Lets get started!
--------------------------------
Ill make a html form so it makes it easier to understand. (Call this breezeform.php if you want.
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
</head>
<body>
<form name="gender" method="post" action="breeze2.php">
Gender:
<input type="radio" name="gender" value="M" />
<strong>Male</strong>
<input type="radio" name="gender" value="F" />
<strong>Female</strong>
<input type="Submit" name="Submit" value="Submit">
</strong>
</form>
</body>
</html>
We can see that where it says action="breeze2.php" goes directly to breeze2.php and executes the php actions in that file.
Make a new php document. (breeze2.php)
And enter in these codes between the body tags:
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
</head>
<body>
<?
if ($gender == 'M') { // If they checked the "Male" button, it prints out:
echo '<b><p>Good day, Sir!</p></b>';
** elseif ($gender == 'F') { // If they checked the "Female" button, it prints out:
echo '<b><p>Good day, Madam!</p></b>';
** else { // If they checked neither, it prints out:
echo '<p><b>You forgot to enter your gender!</b></p>';
**
?>
</body>
</html>
I pretty much explained what the else statements does in the code box.. where i put the // tags
Also, I have to admit why we need those ** and { tags there, but a lot of people/websites say you need them to work something in your php script.
Here are some screenshots to how this else statements work:
You must be registered to see links
You must be registered to see links
If you chose Female, it would print out: "Good day, Madam!"
Now if you DIDN'T choose a gender and pressed Submit:,
You must be registered to see links
it would print out:
You must be registered to see links
Well.. this is pretty much it for my tutorial Have Fun!
-----------------------------------------------------------------
And when im still in PHP i will post the PHP code for stopping SQL Injection:
Code:
<?php
// Quote variable to make safe
function quote_smart($value)
{
// Stripslashes
if (get_magic_quotes_gpc()) {
$value = stripslashes($value);
**
// Quote if not integer
if (!is_numeric($value)) {
$value = "'" . mysql_real_escape_string($value) . "'";
**
return $value;
**
// Connect
$link = mysql_connect('mysql_host', 'mysql_user', 'mysql_password')
OR die(mysql_error());
// Make a safe query
$query = sprintf("SELECT * FROM users WHERE user=%s AND password=%s",
quote_smart($_POST['username']),
quote_smart($_POST['password']));
mysql_query($query);
?>
Ive seen many ask about it so now here it is
Also post youre ideas, basics or tutorial.
Last edited: