0% found this document useful (0 votes)
3 views

WEB PROGRAMMING USING PHP

The document provides an overview of web programming using PHP, covering CSS selectors, PHP data types, operators, SQL commands (CREATE, INSERT, UPDATE, DELETE, SELECT), error handling, and the use of cookies and sessions. It categorizes CSS selectors into five types and explains PHP data types such as strings, integers, and arrays. Additionally, it discusses error handling techniques in PHP and the differences between cookies and sessions for user identification and data storage.

Uploaded by

Shathira mn
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

WEB PROGRAMMING USING PHP

The document provides an overview of web programming using PHP, covering CSS selectors, PHP data types, operators, SQL commands (CREATE, INSERT, UPDATE, DELETE, SELECT), error handling, and the use of cookies and sessions. It categorizes CSS selectors into five types and explains PHP data types such as strings, integers, and arrays. Additionally, it discusses error handling techniques in PHP and the differences between cookies and sessions for user identification and data storage.

Uploaded by

Shathira mn
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

WEB PROGRAMMING USING PHP

CSS selectors:
 We can divide CSS selectors into 5 categories:
1. Simple selectors
2. Combinator selectors
3. Pseudo class selectors
4. Pseudo element selectors
5. Attribute selectors
 CSS selectors are used to find or select the HTML elements you want to style
 Simple selectors select elements based on name, id and class
 Combinator selectors select elements based on a specific relationship between them
 Pseudo class selectors select and style a part of an element
 Whereas pseudo element selectors select elements based on a certain state
 Attribute selectors select elements based on an attribute value

OR
CSS selectors are used to find or select the HTML elements you want to style.

There are several different types of selectors in CSS:

1. CSS element selector:

The element selector selects the element by name.

2. CSS id selector:

The id selector selects the id attribute of an element to select a specific element. An id is


always unique within the page and is written with the hash character followed by the id of
the element.

3. CSS class selector:

The class selector selects elements with a specific class attribute. It is used with a period
character.

4. CSS universal selector:

The universal selector gives the style to all the elements on the page. Symbol used is *.

5. CSS group selector:

The grouping selector is used to give the style to a group or multiple elements with the same
style definitions. It reduces the length of the code.
PHP datatypes:
Data types define the types of data that a variable can store.

PHP supports a wide range of data types, like string, integer, float etc. Data types make it
easier to store and handle information in programs.

1. String:

A string is a sequence of characters, a string is represented inside quotes.

2. Integer:

They represent whole numbers without decimal numbers. It includes either negative and
positive numbers.

3. Float or double:

It is a number with decimal part.

4. Array:

An array stores multiple values in a single variable.

5. Boolean:

A Boolean represents two possible states (true or false). They are often used in conditional
testing.

6. Object:

An object is a specific instance of a class, meaning it is a representation of something that


exists based on the class's definition.

7. NULL:

The special null value is used to represent empty variables in PHP.

8. Resource:

A resource is a special type of variable, holding a reference to an external source.

PHP and javascript operators:


Operators are symbols that are used to perform operations on operands and values.
Different types of operators in php are:

1. Arithmetic operators
2. Comparison operators
3. Logical operators
4. Assignment operators
5. Conditional operators

Arithmetic operators:

These are used to perform mathematical calculations like addition, subtraction,


multiplication, division and modulus.

Comparison operators:

Comparison operators are used to find the relation between the variables.

Logical operators:

Assignment operators:

These operators are used to assign values to variables.


Conditional operators:

CREATE, UPDATE, DELETE, INSERT AND SELECT:


CREATE

The CREATE statement is used to create a table. This includes adding new records where we
can fill in the values.

The syntax foe the CREATE statement is as follows:

CREATE TABLE table_name (record1, record2, record3…);

INSERT

The INSERT statement is used to add new data into a table. It allows you to specify the
values for each column.

The syntax for the INSERT statement is as follows:

INSERT INTO table_name VALUES (value1, value2, value3...);

UPDATE

The UPDATE statement is used to modify existing records in a table. It allows you to change
the values of specific columns based on certain conditions.

The syntax for the UPDATE statement is as follows:

UPDATE table_name SET column1 = value1 WHERE condition;

DELETE
The DELETE statement is used to remove records from a table based on certain conditions. It
allows you to specify which rows you want to delete.

The syntax for the DELETE statement is as follows:

DELETE FROM table_name WHERE condition;

SELECT

The SELECT statement is used to display certain records, group of records or the whole table
(by using *).

The syntax of SELECT statement is as follows:

SELECT * FROM table_name WHERE condition; (displays the whole table);

Error handling in PHP:


Error handling in PHP refers to the making a provision in PHP code to effectively identifying
and recovering from runtime errors that the program might come across. In PHP, the errors
are handled with the help of −

 The die() function

 The Error Handler Function

The die() Function

The die() function is an alias of exit() in PHP. Both result in termination of the current PHP
script when encountered. An optional string if specified in the parenthesis, will be output
before the program terminates.

die("message");

The Error Handler Function

Using die() for error handling is considered an ungainly and poor program design, as it
results in an ugly experience for site users. PHP offers a more elegant alternative with which
you can define a custom function and nominate it for handling the errors.

The set_error_handler() function

PHP cookies and sessions:


Cookie

A cookie is often used to identify a user. A cookie is a small file that the server embeds on
the user's computer. Each time the same computer requests a page with a browser, it will
send the cookie too. With PHP, you can both create and retrieve cookie values.
Create Cookies With PHP

A cookie is created with the setcookie() function.

Sessions:

A session is a way to store information (in variables) to be used across multiple pages.

Unlike a cookie, the information is not stored on the users computer.

When you work with an application, you open it, do some changes, and then you close it.
This is much like a Session. The computer knows who you are. It knows when you start the
application and when you end.

A session is started with the session_start() function.

isset() and unset():

You might also like