BASIC PHP and MYSQL Edward S. Flores.

Slides:



Advertisements
Similar presentations
JQuery MessageBoard. Lets use jQuery and AJAX in combination with a database to update and retrieve information without refreshing the page. Here we will.
Advertisements

PHP I.
Session 1 & 2BBK P1 Module5-May-2007 : [‹#›] PHP: The Basics.
PHP Hypertext Preprocessor Information Systems 337 Prof. Harry Plantinga.
Introduction to PHP MIS 3501, Fall 2014 Jeremy Shafer
Server-Side vs. Client-Side Scripting Languages
IST 221 Internet Concepts and Applications Introduction to PHP.
Introduction to PHP (Part-1) Basharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan. 1.
A Guide to MySQL 3. 2 Objectives Start MySQL and learn how to use the MySQL Reference Manual Create a database Change (activate) a database Create tables.
Dynamic Web site With PHP and MySQL. MySQL The combination of MySQL database and PHP scripting language is optimum for building dynamic websites. MySQL.
8/17/2015CS346 PHP1 Module 1 Introduction to PHP.
PHP Workshop ‹#› PHP: The Basics. PHP Workshop ‹#› What is it? PHP is a scripting language commonly used on web servers. –Stands for “PHP: Hypertext Preprocessor”
PHP Programming. Topics Background and History of PHP Installation Comments in PHP Variables Conditions Loops Functions File Handling Database Handling.
PHP: Hypertext Processor Fred Durao
CSC 318 WEB APPLICATION DEVELOPMENT.  Introduction to Server Scripting language  Client VS Server  Introduction to PHP  PHP Files and Syntax  Function.
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
Programming with php By: Seth Larson. A little bit about PHP  PHP stands for PHP:  Hypertext Preprocessor  PHP is a widely-used general-purpose server-side.
Application Development Description and exemplification of server-side scripting language for server connection, database selection, execution of SQL queries.
Advanced Web 2012 Lecture 4 Sean Costain PHP Sean Costain 2012 What is PHP? PHP is a widely-used general-purpose scripting language that is especially.
ITD 3194 Web Application Development Chapter 4: Web Programming Language.
IDK0040 Võrgurakendused I harjutus 06: PHP: Introduction Deniss Kumlander.
1 PHP and MySQL. 2 Topics  Querying Data with PHP  User-Driven Querying  Writing Data with PHP and MySQL PHP and MySQL.
Nael Alian Introduction to PHP
10/5/2015CS346 PHP1 Module 1 Introduction to PHP.
IST 210: PHP BASICS IST 210: Organization of Data IST210 1.
Web Server Administration Chapter 7 Installing and Testing a Programming Environment.
Class 1Intro to Databases Goals of this class Understand the architecture behind web database applications Gain a basic understanding of what relational.
HTML Hyper Text Markup Language A simple introduction.
Variables and ConstantstMyn1 Variables and Constants PHP stands for: ”PHP: Hypertext Preprocessor”, and it is a server-side programming language. Special.
Intro to PHP IST2101. Review: HTML & Tags 2IST210.
Introduction to PHP Advanced Database System Lab no.1.
A Guide to MySQL 3. 2 Introduction  Structured Query Language (SQL): Popular and widely used language for retrieving and manipulating database data Developed.
NMD202 Web Scripting Week5. What we will cover today PHP & MySQL Displaying Dynamic Pages Exercises Modifying Data PHP Exercises Assignment 1.
IT ELECTIVE 2.  Web server Can refer to either the hardware (the computer) or the software (the computer application) that helps to deliver content that.
Creating a simple database This shows you how to set up a database using PHPMyAdmin (installed with WAMP)
Class 1Intro to Databases Goals of this class Understand the architecture behind web database applications Gain a basic understanding of what relational.
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
1) PHP – Personal Home Page Scripting Language 2) JavaScript.
Spiderman ©Marvel Comics Creating Web Pages (part 1)
IS2803 Developing Multimedia Applications for Business (Part 2) Lecture 2: Introduction to IS2803 Rob Gleasure
PHP Syntax You cannot view the PHP source code by selecting "View source" in the browser - you will only see the output from the PHP file, which is plain.
PHP Form Processing * referenced from
Dr. Abdullah Almutairi Spring PHP is a server scripting language, and a powerful tool for making dynamic and interactive Web pages. PHP is a widely-used,
IST 210: PHP Basics IST 210: Organization of Data IST2101.
HTML Structure II (Form) WEEK 2.2. Contents Table Form.
COM621: Advanced Interactive Web Development Lecture 10 PHP and MySQL.
PHP Basics and Syntax Lesson 3 ITBS2203 E-Commerce for IT.
PHP using MySQL Database for Web Development (part II)
3 A Guide to MySQL.
Introduction to Dynamic Web Programming
CHAPTER 5 SERVER SIDE SCRIPTING
Relational database and SQL MySQL LAMP SQL queries
And Why You Should Use It In You Websites
Chapter 19 PHP Part III Credits: Parts of the slides are based on slides created by textbook authors, P.J. Deitel and H. M. Deitel by Prentice Hall ©
* Lecture # 7 Instructor: Rida Noor Department of Computer Science
PHP / MySQL Introduction
PHP Introduction.
Website Development Basics with PHP MySQL
Intro to PHP & Variables
ISC440: Web Programming 2 Server-side Scripting PHP 3
Title: Tech Training Certificate: Ace of Initiative Program
Module 1 Introduction to PHP 11/30/2018 CS346 PHP.
Intro to PHP.
Tutorial 6 PHP & MySQL Li Xu
Tutorial 10: Programming with javascript
Hypertext Preprocessor
PHP Programming Using Cloud 9 IDE.
PHP By Prof. B.A.Khivsara Note: The material to prepare this presentation has been taken from internet and are generated only for students reference and.
Presentation transcript:

BASIC PHP and MYSQL Edward S. Flores

SQL What is SQL? SQL stands for Structured Query Language SQL allows you to access a database SQL is an ANSI standard computer language SQL can execute queries against a database SQL can retrieve data from a database SQL can insert new records in a database SQL can delete records from a database SQL can update records in a database SQL is easy to learn

PHP What is PHP? PHP originally meant “Personal Home Page” as it was created in 1994 by Rasmus Lerdorf to track the visitors to his online resume. As its usefulness and capabilities grew (and as it started being used in more professional situations), it came to mean “PHP: Hypertext Preprocessor.”

PHP is an HTML embedded scripting language. HTML embedded means that PHP can be interspersed within HTML which makes developing dynamic Web sites more accessible. PHP is scripting language as opposed to a programming language. It is designed to do something only after an event occurs—for example when a user submits a form or goes to a URL. PHP is a server-side, cross-platform technology. Server- side refers to the fact that everything PHP does occurs on the server. Its cross-platform nature means that PHP runs on most operating systems, including Windows, UNIX (any variants), and Macintosh. PHP scripts written on one server will normally work on another with little or no modifications.

What Do I Need?  As mentioned earlier, PHP is a server-side scripting language. This means that, although your users will not need to install new software, you web host will need to have PHP set up on their server. It should be listed as part of your. Writing PHP  Writing PHP on your computer is actually very simple. You don't need any special software, except for a text editor (like Notepad in Windows). Run this and you are ready to write your first PHP script.   Declaring PHP  PHP scripts are always enclosed in between two PHP tags. This tells your server to parse the information between them as PHP. The three different forms are as follows:

<? PHP Code In Here ?> OR <?php PHP Code In Here php?> Declaring PHP <? PHP Code In Here ?> OR <?php PHP Code In Here php?>

PHP Variables As with other programming languages, PHP allows you to define variables. In PHP there are several variable types, but the most common is called a String. It can hold text and numbers. All strings begin with a $ sign. To assign some text to a string you would use the following code: $welcome_text = "Hello and welcome to my website."; This is quite a simple line to understand, everything inside the quotation marks will be assigned to the string. You must remember a few rules about strings though:

Strings are case sensetive so $Welcome_Text is not the same as $welcome_text String names can contain letters, numbers and underscores but cannot begin with a number or underscore When assigning numbers to strings you do not need to include the quotes so:   $user_id = 987 would be allowed.

Outputting Variables To display a variable on the screen, use exactly the same code as to display text but in a slightly different form. The following code would display your welcome text: <? $welcome_text = "Hello and welcome to my website."; Print $welcome_text; ?> As you can see, the only major difference is that you do not need the quotation marks if you are printing a variable.

Formatting Your Text For this example I will change the text to the Arial font in red. The normal code for this would be: <font face="Arial" color="#FF0000"> </font>   As you can see this code contains 4 quotation marks so would confuse the script. Because of this you must add a backslash before each quotation mark to make the PHP script ignore it. The code would change to: <font face=\"Arial\" color=\"#FF0000\"> </font> You can now include this in your print statement: print("<font face=\"Arial\" color\"#FF0000\">Hello and welcome to my website.</font>");

which will make the browser display: Hello and welcome to my website. because it has only been sent the code: <font face="Arial" color="#FF0000">Hello and welcome to my website.</font>   You can also use the code <font face="Arial" color"#FF0000"><? Print “Hello and welcome to my website.”; ?></font>") This will also output the same result.

Getting Started

1. Open a NOTEPAD or DREAMWEAVER. 2. Create a file named index 1. Open a NOTEPAD or DREAMWEAVER. 2. Create a file named index.php and save it in the path C:\xampp\htdocs inside the folder named as your last name. 3. Insert a PHP tag. <? ?> 4. Save the file.

My First PHP with MYSQL Project

Step1. Open the index.php file in myproject folder in the path C:\xampp\htdocs with DREAMWEAVER or NOTEPAD. Step 2. Open a web browser into http://localhost/phpmyadmin Step 3. Create a database named myfriends. Create a table within the database named frnd_names With columns id (5), name (50) and age (3).

Connecting to the Database

Include these PHP codes into the index. php page Include these PHP codes into the index.php page. Host name = “localhost” Server = “root” Password = “ ” or blank Database name = “myfriends” Table name = “ frnd_names” Mysql_connect (“localhost”,”root”,””); Mysql_select_db(“myfriends”);

Adding Values into the Database with PHP

Create a file named add.php and save it in the pages Folder. Step 1. Create a file named add.php and save it in the pages Folder. Step 2. Complete the link in the index.php to show the add.php page Step 3. Insert a FORM (dreamweaver) INSERT -> FORM -> FORM Or (notepad) <form name="form1" method="post" action=""> </form>

create a table with 3 rows and 2 columns. Step 4. create a table with 3 rows and 2 columns. Step 5. Insert the LABELS, TEXT FIELDS and SUBMIT BUTTONS. Rename the TEXT FIELDS as lbl_name and lbl_age. Step 6. Type the FORM ACTION of the page. The FORM ACTION is the file that will handle the data inside the form. <form name="form1" method="post" action=“add_db.php">

Create the file in the FORM ACTION and save it in the pages folder. Step 7. Create the file in the FORM ACTION and save it in the pages folder. Step 8. In the page add_db.php (form action file) call the values of the text fields and store it in a variable. $variable = $_POST[‘TEXT_FIELD_NAME’]; Step 9. Use a SQL query that will add a value into the database. Mysql_query(“insert into tbl_name values (‘value1’,’value2’)”); *You can include the query into a variable for other purposes. *Don’t forget to include the database connection code in this page.

To direct the page to another page after pushing the Step 10. To direct the page to another page after pushing the submit button, use the header format, the variable and an IF statement. IF (something == something else) { THEN Statement } else { ELSE Statement } *You can also use the IF Statement to validate the content of the variable Header (“location: path”);

Viewing the Contents on the Database with PHP

Step 1. Create a file named view. php and save it in the pages Folder Step 1. Create a file named view.php and save it in the pages Folder. Step 2. Complete the link in the index.php to show the view.php Page Step 3. Create 2 tables with 1 row and 2 columns. On the First column, type the word NAME, type the word AGE on the second column.

Mysql_query(“select * from tbl_name where value=‘value’”); Step 4. Use a SQL query and a WHILE STATEMENT that will enable you to view the Contents of a table in a database. Mysql_query(“select * from tbl_name where value=‘value’”); WHILE STATEMENT while (CONDITION) { DO }

Editing the Contents on the Database with PHP

Step 1. Create a file named edit. php and save it in the pages Folder Step 1. Create a file named edit.php and save it in the pages Folder. Step 2. Complete the link in the index.php to show the edit.php Page Step 3. Create 2 tables with 1 row and 3 columns. On the First column, type the word NAME, type the word AGE on the second column and ACTION on the third column.

Mysql_query(“select * from tbl_name where value=value”); Step 4. On the third column on the second table, type the word EDIT and use it as a link to the another page. Step 5. Use a SQL query and a WHILE STATEMENT that will enable you to view the Contents of a table in a database. Mysql_query(“select * from tbl_name where value=value”); WHILE STATEMENT while (CONDITION) { DO } Step 6. Create a file named do_edit.php and save it in the pages Folder.

Insert a FORM (dreamweaver) INSERT -> FORM -> FORM Or (notepad) Step 7. On the do_edit.php file, use a SQL Query and a WHILE STATEMENT to retrieve data from the database. Mysql_query(“select * from tbl_name where value=value”); WHILE STATEMENT while (CONDITION) { DO } Step 8. Insert a FORM (dreamweaver) INSERT -> FORM -> FORM Or (notepad) <form name="form1" method="post" action=""> </form>

Insert the LABELS, TEXT FIELD and SUBMIT BUTTONS. Step 9. Insert the LABELS, TEXT FIELD and SUBMIT BUTTONS. Step 10. Place the values from the WHILE STATEMENT in the TEXT FIELDS. Step 11. Type the FORM ACTION of the page. The FORM ACTION is the file that will handle the data inside the form. <form name="form1" method="post" action=“edit_db.php">

$variable = $_POST[‘TEXT_FIELD_NAME’]; Step 12. Create the file in the FORM ACTION and save it in the pages folder. Step 13. Create a HIDDEN TEXT FIELD in the do_edit.php file containing the ID field. Step 14. In the page edit_db.php call the values of the text fields and store it in a variable. $variable = $_POST[‘TEXT_FIELD_NAME’];

Mysql_query(“update tbl_name set column=‘value1’, column2=‘value2’”); Step 15. Use a SQL query that will update a value on the database. Mysql_query(“update tbl_name set column=‘value1’, column2=‘value2’”); *You can include the query into a variable for other purposes. *Don’t forget to include the database connection code in this page.

Deleting the Contents on the Database with PHP

Step 1. Create a file named delete.php and save it in the pages Folder. Step 2. Complete the link in the index.php to show the delete.php Page Step 3. Create 2 tables with 1 row and 3 columns. On the First column, type the word NAME, type the word AGE on the second column and ACTION on the third column.

Mysql_query(“select * from tbl_name where value=value”); Step 4. On the third column on the second table, type the word DELETE and use it as a link to the another page. Step 5. Use a SQL query and a WHILE STATEMENT that will enable you to view the Contents of a table in a database. Mysql_query(“select * from tbl_name where value=value”); WHILE STATEMENT while (CONDITION) { DO } Step 6. Create a file named do_detete.php and save it in the Pages Folder.

Mysql_query(“delete from tbl_name where column=‘value1’”); Step 7. Use a SQL query that will update a value on the database. Mysql_query(“delete from tbl_name where column=‘value1’”); *You can include the query into a variable for other purposes. *Don’t forget to include the database connection code in this page.

--END-- Edward S. Flores