So, to do my part to change this I decided to make a simple guide on how to handle PHP in the most simple way.
I will explain how to make a dynamic website that is very basic but enough for a kalonline server.
Good links:



Since you are here I assume you have everything you need to do this guide, that is a webserver that can take care of PHP, and a database for a KalOnline server.
Part 1: PHP tags, Echo, Basic Variables
First off you need to create a document called Index.php in your htdocs root folder.
Open it with notepad or any other code editor (I use notepad++).
If you know HTML you know you need opening and closing tags for the code to work. The HTML tag looks like this: <html>
The PHP tag looks a little bit different: <?php
and is closed like this: php?>
code snippet:
PHP Code:
<?php
// some code
// notice that the tags dont have <> on both sides, just php?>
// you can also do like this: ?> <?
// if you don't want to write the php part.
php?>
ECHO.
example:
PHP Code:
<?
echo "hello";
?>
You can either echo like this:
echo "hello";
or
echo 'hello';
The difference is that when you use single quotation marks any text inside them will be sent out like it is, but if you use double, any VARIABLES inside will be sent out. We will come back to this.
I will assume you know what a variable is. You declare a variable like this in php:
PHP Code:
<?
$variablename = "Hello world!";
?>
I will also show the difference between double and single quotation marks in echo now.
PHP Code:
<?
$variable = "hello world";
// echo with double marks
echo "$variable"; // this echo will type out: hello world
// echo with single marks
echo '$variable'; // this echo will type out: $variable
?>
Part 2: Make use of variables. POST and GET
Now how can we make use of these variables?
Well, First off when we get information from a query (for example) we allways store it in a variable, or when we want to check a password of username, or any type of data sent to use for injections, it is allways stored in a variable.
There are two types I will teach you to get information from the CLIENT.
Post.
A post form is for example a login, where you have fields that send information when you press a submit button, that information is caught up by php and stored in variables.
Simple form:
// HTML part
HTML Code:
<form action='submit.php' method='post' enctype='multipart/form-data' /> <input name="account" type="text" id="account"> <br/> <input name="password" type="text" id="password"> <input type="submit" name="Submit" value="submit!" class="ui-state-default ui-corner-all"> </form>
PHP Code:
// PHP part to catch it with a php script
<?
// takes the information from the field called "account"
$account = $_POST['account'];
// takes the information from the field called "password"
$password = $_POST['password'];
?>
Now, when you have done that, you are ready to do things with your variables, remember to secure them if you are using them to login to a DB etc. Otherwise you will have some sql injectors on your hands.
Get.
Another way to get data without a form is through GET.
GET is a function that takes information from the current adress.
For example:

If you want your script to take the informatino after "site=" you type:
$site = $_GET['site'];
The variable $site will now have tha value "forum".
And by now you can guess that if you use:
$site = $_GET['id'];
the value will be "56" instead!
PHP Code:
<?
//adress: http://example.com?site=forum&id=56
$site = $_GET['site']; // value = forum
$site = $_GET['id']; // value = 56
?>
Part 3: MSSQL (Database)
Now we are going to learn how to retrieve some information from a table in the database (the KalOnline database)
We will be using MSSQL for this but alot of other websites use Mysql, but since INIX decided to go with MSSQL we have to use that.
First of all I will go through what you need to do!
1. Connect to the SERVER (link)
2. Select DATABASE
3. Execute query to do something in the database, like a command.
4. Fetch result.
5. Display result.
1. Connect to server
Connecting to the SERVER.(SQL server that is)
The connection function in MSSQL(php) has 3 parameters.
The server name, username to the sql server, and password.
example of a connect:
PHP Code:
<?
// this should connect to your server.
$server = 'SERVERNAME';
$user = 'root';
$pass = 'sa';
$link = mssql_connect($server, $user, $pass);
?>






