0% found this document useful (0 votes)
2 views26 pages

Cs 223 Programming Languages

The document provides an overview of PHP and MySQL, explaining PHP as a server-side scripting language used for web development and MySQL as a relational database management system. It includes instructions for setting up a PHP and MySQL environment, particularly using WAMP, and details on creating and handling HTML forms. Additionally, it covers various HTML elements and their attributes, emphasizing the importance of form validation and user experience.

Uploaded by

aljundagasdas52
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)
2 views26 pages

Cs 223 Programming Languages

The document provides an overview of PHP and MySQL, explaining PHP as a server-side scripting language used for web development and MySQL as a relational database management system. It includes instructions for setting up a PHP and MySQL environment, particularly using WAMP, and details on creating and handling HTML forms. Additionally, it covers various HTML elements and their attributes, emphasizing the importance of form validation and user experience.

Uploaded by

aljundagasdas52
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/ 26

NOTES PROGRAMMING LANGUAGES.

CHAPTER 1
0101-WHAT IS PHP?

PHP (Hypertext Preprocessor) is a widely-used general-purpose scripting language that


is used for Web development. PHP is embedded in HTML pages. There are special
script tags that is used to transform HTML code to PHP code and its main purpose is to
make web pages dynamic. The idea of dynamic is to make display changed based on
something that perhaps the user’s name or account number etc, or perhaps the data
that will help up to. Therefore, DYNAMIC is CHANGING. The good thing about PHP is
that it gonna live on the web page and those thing about HTML (Hypertext Mark up
Language) code, will be just a regular HTML code. But the PHP stuff will give us new
HTML code that will give us new idea depending in the users’ input data in the database.

PHP is also a server-side language, it is design to run on a computer server, or a web


server. It can be developed on a local computer with a special software.

PHP is easy to learn and PHP is also free to download it. PHP code is simpler than other
server language such as Java(J2EE) or MS ASP.

RUNNING IN PHP
• A server must have a Runtime PHP software installed in order to process PHP.
• Generally, the output from a PHP program is an HTML page.
• PHP programs are called Web Page and return new Web Pages to the browser and
the result

Figure 1: A PHP Program in Webpage

0102- WHAT IS MYSQL?


• It is a version of SQL.
• It is generally called “MY SEQUEL”.
• SQL is a unified language for defining, querying, modifying, and controlling the data in a
RELATIONALDATABASE.
0103- WHAT IS A RELATIONAL DATA BASE?
• A relational database
• Stores data in table (grid-like format similar to a spread sheet)
• MySQL is used for structuring, querying and changing information in this tables.
0104- WHAT ARE TABLES?
• They have rows and columns (like spreadsheets and columns)

Figure 2: A sample of Table

CHAPTER 2

Setting up for PHP and MySQL


Requirements
• Computer (about 500MB of Hard Drive Space)
Windows (WAMP)
MacInstoch (MAMP)
Linux (LAMP)

• Plain Text Editor


Textpad for PC
Textwrangler for Mac

• Internet Connection
Research PHP.net
Research MySQL.com (it’s really an Oracle)

Installing WAMP for Windows


Steps in Installing WAMP server for Windows
1. Go to Google Chrome or any browser then tap the search box.
2. Look for WAMP SERVER.
3. Download your WAMP server 64 or 32 bit depending on your computers’ system.
4. In the application you can see a form, you can ignore it and just tap DOWNLOAD DIRECTLY.
5. In the process, you can see an option that states “WOULD YOU LIKE TO SAVE THIS FILE?”,
you just tap
CANCEL to make the process faster.
6. After downloading, go to file and find the application WAMP SERVER and double tap the pink
W icon.
Tap Run in the process of installing so that it can be installed.
7. You better gonna accept the agreement or you can not run the software.
8. To access WAMP directly, better to accept their suggestions.
9. Then install.
10. Navigate to the desired browser and find a folder where you can put or store the files you
created.
11. To finish, you just put your localhost and email if desired.
12. You can launch WAMP server and it is ready to use now.

WAMP stands for:


WINDOWS
APACHE
MySQL
PHP

In the wamp you can find WWW is called directory where you can run programs. In running PHP
programs, go to your local browser and change www to localhost and put the enter key to run it.In
running local host you can see the configuration and some tools, so therefore you can now run
programs on the installed server.

To test the connection of PHP and MySQL, tap testmysql.php and it will work right away.

Figure 3. Testing a simple PHP program

See in Figure 2, there are bunch of errors while running the program, there will be some changes
inside the program. Look at the figure below:
Figure 4: To connect or have access you can just type mysql_connect.

Figure 5: Change hostname to ‘localhost’.

Figure 6: Change dbuser to ‘root’.

Figure 7: To easier access, erase the word dbpassword and just leave it blank ‘ ’
Figure 8: Refresh your local browser and you will find notice that your system is now
connected to your server.

<?php
$link = mysqli_connect ('localhost','root','');
if (!$link) {
die('Could not connect to MySQL; ' . mysqli_error());
}
echo 'Connection OK'; mysqli_close($link);
?>

This is the actual code that is being revise to make the your system accessed on your server.

Using a Hosting service

Figure 9: A Simple Fill up like site using PHP.

Figure 10: A data is being put inside the box for access.
Figure 11: A significance that you are able to run your php code.

Codes need to study:

The program in HTML Code


<!DOCTYPE html>
<html>
<head>
<title>HTML FORMS</title>
<link rel="stylesheet" type="text/css"href="css/basics.css" />
</head>
</h3> WHO ARE YOU?</head>
<body style="background-color: pink;">
<form method="post" action="name.php">
<label for="last_name">Last Name:</label>
<input type="text" id="last_name" name="lastname" required><br>
<label for="first_name">First Name:</label>
<input type="text" id="first_name" name="firstname" required><br>
<label for="middle_initial">Middle Initial:</label>
<input type="text" id="middle_initial" name="middleinitial" required><br>
<input type="submit" value ="Submit Information" />

Code in PHP Code

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
<head>
<title>HTML Forms</title>
<link rel="stylesheet" type="text/css" href="css/basic.css"/>
</head>

<body style="background-color: silver;">

<h3>Success!</h3>

<?php
$firstname = $_POST['firstname'];
print "<p>Congratulations $firstname</p>";
?>

<p>You've just written your first PHP program!</p>

</body>
</html>

Figure 12

Figure 13
Figures 12 and 13 the actual output of the program in HTML and PHP forms.

Chapter 3
Using a PHP Print Tags

It is being emphasized that NOTHING happens when a WAMP server is being


started.

Figure 14: A error is being observed in a localhost

Observe Figure 13 it is being observed that the localhost is unable to connect is


because the WAMP server is not being started. Therefore, nothing happens at all.

Figure 15: A WAMP server is being activated


To start WAMP server, just go to your windows and tap start WAMP server. Once
it is being started, we can see an orange box changing its color from red to orange
to green indicates that server is ready.

<html>
<head><title>0301 Usinh PHP Scrip.Tags</title>
<style>body {font-family: Arial, Helvetica, sans-serif; font-size: 16px;}</style>

<body>
<hl>0301 Using PHP Script Tags</hl>
<p>What are script tags and why do we need them to run PHP?</p>

<?php
$today = date('y-m-d h:g:s');
print "<p><b>Today is $today </b></p>";
?>
<p>Do you want to see that again?</p>
<?php
print "<p><b>Today is STILL $today </B></p>";
?>
</body>

</html>

Figure 16: The final outcome in the HTML code

0301 – Using PHP Script Tags


• Opening and Closing Tags:
• PHP code is enclosed within <?php (opening tag) and ?> (closing tag).
• Inline Code:
• PHP code can be embedded directly within HTML tags.
• Echo Statement:
• echo/print is used to output content to the browser.
• Variables:
• PHP variables start with the dollar sign $.
• Control Structures:
• PHP supports various control structures like if statements, loops, etc.
• Comments:
• Comments in PHP are similar to those in other programming languages.
Remember to configure your server to process PHP files and ensure that PHP is
properly installed.

0302 – Displaying HTML to your Browser Window


• Creating an HTML Document:
• An HTML document starts with <!DOCTYPE html> to define the document
type.
• The HTML content is enclosed between <html> and </html> tags.
• Head Section:
• The <head> section contains meta-information about the document, such as title,
character set, and linked stylesheets.
• The page title is set using the <title> tag within the head.
• Body Section:
• The main content of the page is placed within the <body> and </body> tags.
• HTML tags within the body define the structure and presentation of the content.
• Text Formatting:
• Tags like <p> for paragraphs, <h1> to <h6> for headings, and <strong> or
<b>for
bold text help format text.
• Links:
• Hyperlinks are created using the <a> tag. The href attribute specifies the URL.
• Images:
• Images are displayed with the <img> tag. The src attribute contains the path to
the image file.
• Forms:
• Forms are created with the <form> tag. Form elements include input fields,
buttons, and other controls.
• Displaying HTML Locally:
• Save your HTML file with a .html extension.
• Open the file in a web browser to view the rendered HTML.
• Web Hosting:
• To share your HTML page on the internet, you need web hosting. Many platforms offer free hosting for
static HTML pages.

Remember to validate your HTML using tools like the W3C Markup Validation
Service and test it on multiple browsers to ensure consistent display.

0303 – HTML Forms


• Form Basics:
• HTML forms are used to collect user input on a webpage.
Forms are created using the <form> and </form> tags
• Form Elements:
• Input fields, checkboxes, radio buttons, text areas, buttons, and more are
used as form elements.
• Input Fields:
• Common input types include text (<input type="text">), password (<input
type="password">), email (<input type="email">), and more.
• The name attribute is crucial for identifying form data when submitted.
• Labels:
• Use the <label> element to associate text labels with form elements.
Improves accessibility.
• Text Areas:
• For multiline text input, use the <textarea> tag. The size is controlled by
attributes like rows and cols.
• Radio Buttons and Checkboxes:
• Radio buttons (<input type="radio">) are used for selecting one option from
a group. They share the same name attribute.
• Checkboxes (<input type="checkbox">) allow users to select multiple options.
• Dropdown Menus:
• The <select> element creates a dropdown menu, and <option> elements
define the menu options.
• Buttons:
• Buttons can be created using <button> or <input type="button">. They can
trigger form submission or custom JavaScript functions.
• Form Submission:
• The action attribute in the <form> tag specifies the URL where the form data
is sent.
• The method attribute defines the HTTP method (GET or POST) used to submit
the form.
• Styling Forms:
CSS can be used to style form elements and improve the overall look and feel.
Remember to test your forms thoroughly, considering different scenarios and user
inputs. Form handling on the server side is also crucial for processing and storing
user-submitted data securely.

0304 – Using Select Tag


• Select Tag Basics:
• The <select> tag is used to create a dropdown menu or a list box on a form.
• It contains one or more <option> elements that represent the available
choices in the list.
• Option Elements:
• The <option> tag is used within the <select> element to define each item in
the dropdown list.
• The text content between the opening and closing <option> tags is what
appears in the dropdown.
• Selecting a Default Option:
• Use the selected attribute within an <option> tag to preselect an option
when the page loads.
• Multiple Selection:
• For allowing users to select multiple options, add the multiple attribute to
the <select> tag.
• Use the size attribute to specify the number of visible options when multiple
is enabled
• Grouping Options:
• Options can be grouped within the <optgroup> tag. It helps organize and
structure the options in the dropdown.
• Setting Values:
• Use the value attribute within the <option> tag to assign a specific value to
each option. This value is sent when the form is submitted.
• Using the Size Attribute:
The size attribute can be added to the <select> tag to control the number of
visible options without using the multiple attribute.
• Styling Select Boxes:
• Styling can be applied to <select> elements using CSS to enhance the visual
appearance.
• Form Submission:
• When the form is submitted, the selected value(s) from the <select> element
are sent to the server for processing.
Remember to test your dropdowns thoroughly in various scenarios, considering
different browsers and devices. Well-structured and user-friendly drop downs
contribute to a positive user experience on your web forms.

0305 – Using TextArea Tag


• Textarea Basics:
• The <textarea> tag in HTML is used to create a multiline text input field.
• It is commonly used for allowing users to enter longer pieces of text, such as
comments or descriptions.
• Textarea Attributes:
• The rows and cols attributes in the <textarea> tag define the number of
visible rows and columns, respectively.
• The name attribute is crucial for identifying the text area when the form is
submitted.
• Disabled Textarea:
• The disabled attribute can be added to the <textarea> to make it read-only
and prevent user input.
• Styling Textareas:
• CSS can be used to style the <textarea> element, adjusting its appearance
and dimensions.
• Resizable Textareas:
By default, most browsers allow users to resize textareas. You can use CSS to
control or disable this feature.
• Use Cases:
• Textareas are suitable for scenarios where users need to provide more
extended text input, such as comments, reviews, or messages.
Remember to test your textareas thoroughly in various scenarios, considering
different browsers and devices. A well-designed textarea enhances the overall user
experience on your web forms.
0306 – Using Radio Button
• Radio Button Basics:
• The <input type="radio"> element is used to create radio buttons in HTML.
• Radio buttons are part of a group, and users can select only one option from
the group.
• Grouping Radio Buttons:
• Radio buttons are grouped using the name attribute. All radio buttons with
the same name belong to the same group.
• Only one radio button in a group can be selected at a time.
• Radio Button Attributes:
• The value attribute in the <input> tag is used to assign a specific value to the
selected radio button. This value is sent to the server when the form is
submitted.
• Default Selection:
• You can use the checked attribute to preselect a radio button when the page
loads.
• Use Cases:
• Radio buttons are suitable for scenarios where users need to choose a single
option from a set of mutually exclusive choices, such as gender or
subscription type.
• Validation:
Ensure that users select a valid option from the radio button group.
Implement additional validation on the server side if necessary.
Remember to test your radio buttons thoroughly in various scenarios, considering
different browsers and devices. Well-designed radio button groups contribute to a
clear and intuitive user experience on your web forms.
0307 – Using Checkbox Tag
• Checkbox Basics:
• The <input type="checkbox"> element is used to create checkboxes in HTML.
• Checkboxes allow users to select multiple options from a set.
• Checkbox Attributes:
• The name attribute is used to group checkboxes together. All checkboxes with
the same name belong to the same group.
• The value attribute in the <input> tag assigns a specific value to the checkbox.
This value is sent to the server when the form is submitted.
• Default Selection:
• You can use the checked attribute to preselect a checkbox when the page
loads.
• Use Cases:
• Checkboxes are suitable for scenarios where users need to choose multiple
options from a set, such as selecting preferences or items from a list.
• Indeterminate State:
• Checkboxes can have an indeterminate state. This state is often used when a
checkbox group has mixed selected and unselected options.
Remember to test your checkboxes thoroughly in various scenarios, considering
different browsers and devices. Well-designed checkbox groups contribute to a
clear and intuitive user experience on your web forms.
0308 Assigning Values to Variables
0309 Appending Text
0310 Debugging Technique- Part 1
0311 Assignment 1
Formatted: Normal, Indent: Left: 0 cm

You might also like