• Unfortunately, we have experienced significant hard drive damage that requires urgent maintenance and rebuilding. The forum will be a state of read only until we install our new drives and rebuild all the configurations needed. Please follow our Facebook page for updates, we will be back up shortly! (The forum could go offline at any given time due to the nature of the failed drives whilst awaiting the upgrades.) When you see an Incapsula error, you know we are in the process of migration.

L2J [Guide] Php with html and mysql combination

Elite Diviner
Joined
Dec 23, 2006
Messages
492
Reaction score
0
Well in this guide you will not learn something that will help you with your server but it will make you understand the php basics and how to use it with mysql and html so you will have a help to make your own web site for your server

I made this guide because many users ask me to do that
I hope not spamming in this thread.If you dont like it please dont post.I believe that only the guys that read the guide carefully and want to say a thank or post a thing that they dont understand
may post
What is PHP?


  • PHP stands for PHP: Hypertext Preprocessor
  • PHP is a server-side scripting language, like ASP
  • PHP scripts are executed on the server
  • PHP supports many databases (MySQL, Informix, Oracle, Sybase, Solid, PostgreSQL, Generic ODBC, etc.)
  • PHP is an open source software (OSS)
  • PHP is free to download and use
However we will talk on this guide only for mysql becaue l2j support it

What is a PHP File?

  • PHP files may contain text, HTML tags and scripts
  • PHP files have a file extension of ".php", ".php3", or ".phtml"
What is MySQL?


  • MySQL is a database server
  • MySQL is ideal for both small and large applications
  • MySQL supports standard SQL
  • MySQL compiles on a number of platforms
  • MySQL is free to download and use
PHP + MySQL

  • PHP combined with MySQL are cross-platform (means that you can develop in Windows and serve on a Unix platform)
Where Software i need?

  • Install an Apache server on a Windows or Linux machine
  • Install PHP on a Windows or Linux machine
  • Install MySQL on a Windows or Linux machine
Basic PHP Syntax

A PHP scripting block always starts with <?php and ends with ?>. A PHP scripting block can be placed anywhere in the document.
On servers with shorthand support enabled you can start a scripting block with <? and end with ?>.
However, for maximum compatibility, we recommend that you use the standard form (<?php) rather than the shorthand form.
<?php ?> A PHP file normally contains HTML tags, just like an HTML file, and some PHP scripting code.
Below, we have an example of a simple PHP script which sends the text "Hello World" to the browser:
<html>
<body> <?php
echo "Hello World";
?> </body>
</html> Each code line in PHP must end with a semicolon. The semicolon is a separator and is used to distinguish one set of instructions from another.
There are two basic statements to output text with PHP: echo and print. In the example above we have used the echo statement to output the text "Hello World".
Comments in PHP

In PHP, we use // to make a single-line comment or /* and */ to make a large comment block.
<html>
<body> <?php //This is a comment /*
This is
a comment
block
*/ ?> </body>

Variables in PHP

Variables are used for storing a values, like text strings, numbers or arrays.
When a variable is set it can be used over and over again in your script
All variables in PHP start with a $ sign symbol.
The correct way of setting a variable in PHP:
$var_name = value; New PHP programmers often forget the $ sign at the beginning of the variable. In that case it will not work.
Let's try creating a variable with a string, and a variable with a number:
<?php $txt = "Hello World!"; $number = 16; ?>

Strings in PHP

String variables are used for values that contains character strings.
In this tutorial we are going to look at some of the most common functions and operators used to manipulate strings in PHP.
After we create a string we can manipulate it. A string can be used directly in a function or it can be stored in a variable.
Below, the PHP script assigns the string "Hello World" to a string variable called $txt:
<?php
$txt="Hello World";
echo $txt;
?> The output of the code above will be:
Hello World Now, lets try to use some different functions and operators to manipulate our string.
The Concatenation Operator

There is only one string operator in PHP.
The concatenation operator (.) is used to put two string values together.
To concatenate two variables together, use the dot (.) operator:
<?php
$txt1="Hello World";
$txt2="1234";
echo $txt1 . " " . $txt2;
?> The output of the code above will be:
Hello World 1234 If we look at the code above you see that we used the concatenation operator two times. This is because we had to insert a third string.
Between the two string variables we added a string with a single character, an empty space, to separate the two variables.

Using the strlen() function

The strlen() function is used to find the length of a string.
Let's find the length of our string "Hello world!":
<?php
echo strlen("Hello world!");
?> The output of the code above will be:
12 The length of a string is often used in loops or other functions, when it is important to know when the string ends. (i.e. in a loop, we would want to stop the loop after the last character in the string)
Using the strpos() function

The strpos() function is used to search for a string or character within a string.
If a match is found in the string, this function will return the position of the first match. If no match is found, it will return FALSE.
Let's see if we can find the string "world" in our string:
<?php
echo strpos("Hello world!","world");

?> The output of the code above will be:
6 As you see the position of the string "world" in our string is position 6. The reason that it is 6, and not 7, is that the first position in the string is 0, and not 1.


</html>


Control Structures



Any PHP script is built out of a series of statements. A statement can be an assignment, a function call, a loop, a conditional statement of even a statement that does nothing (an empty statement). Statements usually end with a semicolon. In addition, statements can be grouped into a statement-group by encapsulating a group of statements with curly braces. A statement-group is a statement by itself as well. The various statement types are described in this chapter.
if

The if construct is one of the most important features of many languages, PHP included. It allows for conditional execution of code fragments. PHP features an if structure that is similar to that of C:
if (expr)

The following example would display a is bigger than b if $a is bigger than $b:
<?php if ($a > $b) print "a is bigger than b"; ?>

Often you'd want to have more than one statement to be executed conditionally. Of course, there's no need to wrap each statement with an if clause. Instead, you can group several statements into a statement group. For example, this code would display a is bigger than b if $a is bigger than $b, and would then assign the value of $a into $b:
<?php
if ($a > $b) {
print "a is bigger than b";
$b = $a;
}
?>
If statements can be nested indefinitely within other if statements, which provides you with complete flexibility for conditional execution of the various parts of your program.


statement

MySQL Functions


Requirements

In order to have these functions available, you must compile PHP with MySQL support.
Installation

By using the --with-mysql[=DIR] configuration option you enable PHP to access MySQL databases.
In PHP 4, the option --with-mysql is enabled by default. To disable this default behavior, you may use the --without-mysql configure option. Also in PHP 4, if you enable MySQL without specifying the path to the MySQL install DIR, PHP will use the bundled MySQL client libraries. In Windows, there is no DLL, it's simply built into PHP 4. Users who run other applications that use MySQL (for example, auth-mysql) should not use the bundled library, but rather specify the path to MySQL's install directory, like so: --with-mysql=/path/to/mysql. This will force PHP to use the client libraries installed by MySQL, thus avoiding any conflicts.
In PHP 5, MySQL is no longer enabled by default, nor is the MySQL library bundled with PHP



Runtime Configuration

The behaviour of these functions is affected by settings in php.ini.

Table 1. MySQL Configuration Options
NameDefaultChangeablemysql.allow_persistent"On"PHP_INI_SYSTEMmysql.max_persistent"-1"PHP_INI_SYSTEMmysql.max_links"-1"PHP_INI_SYSTEMmysql.default_portNULLPHP_INI_ALLmysql.default_socketNULLPHP_INI_ALLmysql.default_hostNULLPHP_INI_ALLmysql.default_userNULLPHP_INI_ALLmysql.default_passwordNULLPHP_INI_ALLmysql.connect_timeout"0"PHP_INI_SYSTEM


MySQL fetch constants
constantdescriptionMYSQL_ASSOC Columns are returned into the array having the fieldname as the array index. MYSQL_BOTH Columns are returned into the array having both a numerical index and the fieldname as the array index. MYSQL_NUM Columns are returned into the array having a numerical index to the fields. This index starts with 0, the first field in the result.
Example 1. MySQL extension overview example

<?php
/* Connecting, selecting database */
$link = mysql_connect("mysql_host", "mysql_user", "mysql_password")
or die("Could not connect : " . mysql_error());
print "Connected successfully";
mysql_select_db("my_database") or die("Could not select database");

/* Performing SQL query */
$query = "SELECT * FROM my_table";
$result = mysql_query($query) or die("Query failed : " . mysql_error());

/* Printing results in HTML */
print "<table>\n";
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
print "\t<tr>\n";
foreach ($line as $col_value) {
print "\t\t<td>$col_value</td>\n";
}
print "\t</tr>\n";
}
print "</table>\n";

/* Free resultset */
mysql_free_result($result);

/* Closing connection */
mysql_close($link);

HTTP authentication with PHP




The HTTP Authentication hooks in PHP are only available when it is
running as an Apache module and is hence not available in the CGI version.
In an Apache module PHP script, it is possible to use the header()
unction to send an "Authentication Required"
message to the client browser causing it to pop up a Username/Password
input window.

Example 2. HTTP Authentication example

<?php
if (!isset($_SERVER['PHP_AUTH_USER'])) {
header('WWW-Authenticate: Basic realm="My Realm"');
header('HTTP/1.0 401 Unauthorized');
echo 'Text to send if user hits Cancel button';
exit;
} else {
echo "<p>Hello {$_SERVER['PHP_AUTH_USER']}.</p>";
echo "<p>You entered {$_SERVER['PHP_AUTH_PW']} as your password.</p>";
}

Compatibility Note: Please be careful when coding the HTTP header lines. In order to guarantee maximum compatibility with all clients, the keyword "Basic" should be written with an uppercase "B", the realm string must be enclosed in double (not single) quotes, and exactly one space should precede the 401 code in the HTTP/1.0 401 header line.
Instead of simply printing out PHP_AUTH_USER and PHP_AUTH_PW, as done in the above example, you may want to check the username and password for validity. Perhaps by sending a query to a database, or by looking up the user in a dbm file.
Watch out for buggy Internet Explorer browsers out there. They seem very picky about the order of the headers. Sending the WWW-Authenticate header before the HTTP/1.0 401 header seems to do the trick for now.

Improved MySQL Extension

The mysqli extension allows you to access the functionality provided by MySQL 4.1 and above. More information about the MySQL Database server can be found at

Installation

To install the mysqli extension for PHP, use the --with-mysqli=mysql_config_path configuration option where mysql_config_path represents the location of the mysql_config program that comes with MySQL versions greater than 4.1. Also, disable the standard MySQL extension (which is enabled by default) by also using the --without-mysql configuration option. If you would like to install the standard mysql extension along with the mysqli extension, the bundled libmysql library that comes with PHP cannot be used. Instead, use the client libraries installed by MySQL with versions below 4.1. This will force PHP to use the client libraries installed by MySQL thus avoiding any conflicts.
Runtime Configuration

The behaviour of these functions is affected by settings in php.ini.

Table 1. MySQLi Configuration Options
Name Default Changeable
mysqli.max_links "-1" PHP_INI_SYSTEM
mysqli.default_port NULL PHP_INI_ALL
mysqli.default_socket NULL PHP_INI_ALL
mysqli.default_host NULL PHP_INI_ALL
mysqli.default_user NULL PHP_INI_ALL
mysqli.default_pw NULL PHP_INI_ALL

Resource Types
mysqli_link

Represents a connection between PHP and a MySQL database.
mysqli_stmt

Represents a prepared statement.
mysqli_result

Represents the result set obtained from a query against the database.

PHP / Java Integration

There are two possible ways to bridge PHP and Java: you can either integrade php with java enviroment which is the more stable and efficient solution, or integrate Java support into PHP. The former is provided by a SAPI module that interfaces with the Servlet server, the latter by this Java extension.

The Java extension provides a simple and effective means for creating and invoking methods on Java objects from PHP. The JVM is created using JNI, and everything runs in-process.

Installation

To include Java support in your PHP build you must add the option --with-java[=DIR] where DIR points to the base install directory of your JDK. This extension can only be built as a shared dl. More build instructions for this extension can be found in php4/ext/java/README.

Runtime Configuration

The behaviour of these functions is affected by settings in php.ini.

Table 1. Java configuration options
Name Default Changeable
java.class.path NULL PHP_INI_ALL
java.home NULL PHP_INI_ALL
java.library.path NULL PHP_INI_ALL
java.library JAVALIB PHP_INI_ALL

Example 3. Java Example

<?php
// get instance of Java class java.lang.System in PHP
$system = new Java('java.lang.System');

// demonstrate property access
print 'Java version='.$system->getProperty('java.version').' <br>';
print 'Java vendor=' .$system->getProperty('java.vendor').' <br>';
print 'OS='.$system->getProperty('os.name').' '.
$system->getProperty('os.version').' on '.
$system->getProperty('os.arch').' <br>';

// java.util.Date example
$formatter = new Java('java.text.SimpleDateFormat',
"EEEE, MMMM dd, yyyy 'at' h:mm:ss a zzzz");

print $formatter->format(new Java('java.util.Date'));
?>

Notes:

*

new Java() will create an instance of a class if a suitable constructor is available. If no parameters are passed and the default constructor is useful as it provides access to classes like java.lang.System which expose most of their functionallity through static methods.
*

Accessing a member of an instance will first look for bean properties then public fields. In other words, print $date.time will first attempt to be resolved as $date.getTime(), then as $date.time.
*

Both static and instance members can be accessed on an object with the same syntax. Furthermore, if the java object is of type java.lang.Class, then static members of the class (fields and methods) can be accessed.
*

Exceptions raised result in PHP warnings, and NULL results. The warnings may be eliminated by prefixing the method call with an "@" sign. The following APIs may be used to retrieve and reset the last error:

#

Overload resolution is in general a hard problem given the differences in types between the two languages. The PHP Java extension employs a simple, but fairly effective, metric for determining which overload is the best match.

Additionally, method names in PHP are not case sensitive, potentially increasing the number of overloads to select from.

Once a method is selected, the parameters are cooerced if necessary, possibly with a loss of data (example: double precision floating point numbers will be converted to boolean).
#

In the tradition of PHP, arrays and hashtables may pretty much be used interchangably. Note that hashtables in PHP may only be indexed by integers or strings; and that arrays of primitive types in Java can not be sparse. Also note that these constructs are passed by value, so may be expensive in terms of memory and time.



I hope i help people who needs to learn and not leaching



Credits
Google
 
Junior Spellweaver
Joined
Aug 11, 2006
Messages
158
Reaction score
1
Re: [Share] Php guide with html and mysql combination

nice that helps a bit, now if i can get acm into one page of my e107 website :D thanks!
 
Junior Spellweaver
Joined
Oct 29, 2005
Messages
185
Reaction score
0
Re: [Share] Php guide with html and mysql combination

very nice, EzEraL
thank you
 
Newbie Spellweaver
Joined
Nov 6, 2006
Messages
96
Reaction score
0
Re: [Share] Php guide with html and mysql combination

woot, awesome! thats what i need to learn php extra l2, all i no is to config my simple web sites xD

Thank you very much!
 
Back
Top