This document provides an overview of setting up a local web server with PHP and MySQL using XAMPP. It discusses installing XAMPP, the basic syntax of PHP, embedding PHP code in HTML, variables, forms, connecting to MySQL databases, and including files. Key points include that PHP code is placed between <?php ?> tags, variables start with $, forms are defined with <form> tags and have attributes like action and method, and MySQL is used to store and access data in databases. Files can be included in other PHP files using include() or require().
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
32 views
Session 5
This document provides an overview of setting up a local web server with PHP and MySQL using XAMPP. It discusses installing XAMPP, the basic syntax of PHP, embedding PHP code in HTML, variables, forms, connecting to MySQL databases, and including files. Key points include that PHP code is placed between <?php ?> tags, variables start with $, forms are defined with <form> tags and have attributes like action and method, and MySQL is used to store and access data in databases. Files can be included in other PHP files using include() or require().
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5
SESSION 5 the PHP engine to treat the enclosed
PHP AD MYSQL code block as PHP code, rather than
simple HTML SETTING UP A LOCAL WEB SERVER
PHP script execute on a web server
running PHP. So before you start writing any PHP program you need the following program installed on your computer. Every PHP statement end with a semicolon The Apache Web server (;) —this tells the PHP engine that the end The PHP engine of thecurrent statement has been reached. The MySQL database server To save your file: XAMPP c://xampp/htdocs/folder XAMPP is a free and open-source cross- To access your file: platform web server solution stack package localhost/folder/name of your file developed by Apache Friends, consisting EMBEDDING PHP WITHIN HTML mainly of the Apache HTTP Server, MariaDB database, and interpreters for PHP files are plain text files scripts written in the PHP and Perl with .php extension. Inside a PHP programming languages. file you can write HTML like you do in regular HTML pages as well as The official website for downloading embed PHP codes for server side and installation instructions for the XAMPP: execution. https://www.apachefriends.org/ download.html When you run the code the PHP All files must be put in the engine executed the instructions xampp/htdocs/directory between the <?php ... ?> tags and e.g. c://xampp/htdocs/airlines leave rest of the thing as it is. “airlines” is the name of the folder
PHP COMMENTS
A comment is simply text that is
PHP SYNTAX ignored by the PHP engine. To write a single-line comment either A PHP script starts with the <?php start the line with either // or # and ends with the ?> tag. To write multi-line comments, start The PHP delimiter <?php and ?> in the comment with a /* */ the following example simply tells A variable name cannot contain spaces. Case sensitive PHP CASE SENSITIVE Variable names in PHP are case-sensitive. However the keywords, function and classes names are case-insensitive
PHP VARIABLES Variables are used to store data, like string of text, numbers, etc. Variable values can change over the course of a script. Important things to know about variables:
In PHP, a variable does not need to
be declared before adding a value to PHP ECHO STATEMENT it. PHP automatically converts the variable to the correct data type, The echo statement can output one depending on its value. or more strings. After declaring a variable it can be The echo statement can display reused throughout the code. anything that can be displayed to the The assignment operator (=) used to browser, such as string, numbers, assign value to a variable. variables values, the results of expressions etc. Since echo is a language construct not actually a function (like if statement), you can use it without parentheses e.g. echo or echo().
These are the following rules for naming a
PHP variable:
All variables in PHP start with a $
sign, followed by thename of the variable. A variable name must start with a letter or the underscore character _. A variable name cannot start with a number. A variable name in PHP can only contain alpha-numericcharacters and underscores (A-z, 0-9, and _). FORM ELEMENTS
Input – text, radio, checkbox, submit,
button Select Button Text Area FORM ELEMENTS ATTRIBUTES TYPE PHP and HTML FORMS The HTML <form> element defines a form that is used to collect user input <form> NAME - Each input field must have a name attribute to be submitted. form elements If the name attribute is omitted, the </form> data of that input field will not be sent at all. Attributes – action, method, target ACTION
The action attribute defines the
action to be performed when the form is submitted. Normally, the form data is sent to a web page on theserver when the user clicks on the submit button. TARGET
The target attribute specifies if the
submitted result will open in a new browser tab, a frame, or in the current window. (_blank, _self) METHOD
The method attribute specifies the MYSQL
HTTP method (GET or POST) to be used when submitting the form data. MySQL is the most popular database system used with PHP. GET - the submitted form data will be visible MySQL is a database system used in the page address field on the web POST - form data contains sensitive or MySQL is a database system that personal information. The POST method runs on a server does not display the submitted form data in MySQL is very fast, reliable, and the page address field. easy to use MySQL uses standard SQL The connection to the MySQL MySQL compiles on a number of database server will be closed platforms automatically as soon as the MySQL is free to download and use execution of the script ends. MySQL is developed, distributed, However, if you want to close it and supported by Oracle earlier you can do this by simply Corporation calling the PHP mysqli_close() MySQL is named after co-founder function. Monty Widenius's daughter: My
INCLUDING A PHP FILE INTO ANOTHER
PHP FILE The include()and require()statement allow you to include the code contained in a PHP file within another PHP file. In order to store or access the data inside a MySQL database, you first need to connect Including a file produces the same result as to the MySQL database server. copying the script from the file specified and pasted into the location where it is called. PHP offers two different ways to connect to MySQL server MySQLi (Improved MySQL) PDO (PHP Data Objects) extensions. Syntax: MySQLi, Procedural way
Syntax: MySQLi, Object Oriented way
Syntax: PHP Data Objects (PDO) way
The index.php files includes header, menu and footer file