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.

Slides:



Advertisements
Similar presentations
PHP I.
Advertisements

PHP and MySQL Database. Connecting to MySQL Note: you need to make sure that you have MySQL software properly installed on your computer before you attempt.
1 Database Driven Web Application Clients Application Servers including web servers Database Server Traditional client-server (2-tier architecture): client:
Everyday Italian Giada De Laurentiis Harry Potter J K. Rowling Learning XML Erik T. Ray CSCI 305 Introduction to Database.
Outline IS400: Development of Business Applications on the Internet Fall 2004 Instructor: Dr. Boris Jukic PHP.
2440: 141 Web Site Administration Web Server-Side Programming Professor: Enoch E. Damson.
1 CS428 Web Engineering Lecture 18 Introduction (PHP - I)
WHAT IS PHP PHP is an HTML-embedded scripting language primarily used for dynamic Web applications.
PHP By Dr. Syed Noman Hasany. PHP PHP was originally created by Rasmus Lerdorf in PHP stands for PHP: Hypertext Preprocessor (a recursive acronym).
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide
PHP: Hypertext Processor Fred Durao
SJSU CS157B Dr. Lee1  2004 Jenny Mitchell Two Useful Tools You Can’t Live Without by Jenny Mitchell SJSU CS157B Section PHP and MySQL.
CSC 318 WEB APPLICATION DEVELOPMENT.  Introduction to Server Scripting language  Client VS Server  Introduction to PHP  PHP Files and Syntax  Function.
Application Development Description and exemplification of server-side scripting language for server connection, database selection, execution of SQL queries.
Introduction to PHP and Server Side Technology. Slide 2 PHP History Created in 1995 PHP 5.0 is the current version It’s been around since 2004.
PHP Tutorial By RAY BALIKI && ROY GHORAYEB. DEFINITION PHP is a powerful server-side scripting language for creating dynamic and interactive websites.
Mandakini Ayushi Infotech Mandakini Kumari 22 nd July PHP Basic.
PHP - Hypertext Preprocessor. Introduction PHP is a powerful server-side scripting language for creating dynamic and interactive websites. PHP is a powerful.
SCV1223 PHP - Hypertext Preprocessor. Introduction PHP is a powerful server-side scripting language for creating dynamic and interactive websites. PHP.
MySQL in PHP – Page 1 of 17CSCI 2910 – Client/Server-Side Programming CSCI 2910 Client/Server-Side Programming Topic: MySQL in PHP Reading: Williams &
Languages in WEB Presented by: Jenisha Kshatriya BCM SS09.
IDK0040 Võrgurakendused I harjutus 06: PHP: Introduction Deniss Kumlander.
INTERNET APPLICATION DEVELOPMENT For More visit:
1 PHP and MySQL. 2 Topics  Querying Data with PHP  User-Driven Querying  Writing Data with PHP and MySQL PHP and MySQL.
NMED 3850 A Advanced Online Design January 26, 2010 V. Mahadevan.
Nael Alian Introduction to PHP
PHP With Oracle 11g XE By Shyam Gurram Eastern Illinois University.
Creating Dynamic Web Pages Using PHP and MySQL CS 320.
Web Scripting [PHP] CIS166AE Wednesdays 6:00pm – 9:50pm Rob Loy.
1. Connecting database from PHP 2. Sending query 3. Fetching data 4. Persistent connections 5. Best practices.
Lecture 10 – MYSQL and PHP (Part 2)
Technology & Management Club Development Software Overview.
Open Source Software Unit – 3 Presented By Mr. R.Aravindhan.
1Computer Sciences Department Princess Nourah bint Abdulrahman University.
Overview: 1. Discussion of the basic architecture of a web application. 2. Discussion of the relevance of using MySQL and PHP in a web application.
PHP ( PHP: Hypertext Preprocessor)PHP ( PHP: Hypertext Preprocessor) Much of its syntax is borrowed from C, Java, and Perl.Much of its syntax is borrowed.
HTML, PHP, and MySQL: Putting It All Together. Making a Form Input tags Types: “text” “radio” “checkboxes” “submit”
PHP. 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.
Introduction to PHP Advanced Database System Lab no.1.
Web Technology Introduction to PHP. PHP PHP stands for PHP Hypertext Preprocessor PHP is a Server-Side Web Scripting language, which executes on the web.
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.
Introduction to Web Programming. Introduction to PHP What is PHP? What is a PHP File? What is MySQL? Why PHP? Where to Start?
Introduction to PHP.
הרצאה 4. עיבוד של דף אינטרנט דינמי מתוך Murach’s PHP and MySQL by Joel Murach and Ray Harris.  דף אינטרנט דינמי משתנה עפ " י הרצת קוד על השרת, יכול להשתנות.
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.
PHP Introduction PHP is a server-side scripting language.
8 th Semester, Batch 2009 Department Of Computer Science SSUET.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 14 Web Database Programming Using PHP.
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.
Introduction to PHP 1.What is PHP? What Is PHP?  php: hypertext preprocessor  Server-side scripting language—like ASP—scripts are executed on server.
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,
Web Page Designing With Dreamweaver MX\Session 1\1 of 9 Session 1 Introduction to PHP Hypertext Preprocessor - PHP.
PHP stands for …….. “PHP Hypertext Pre-processor” and is a server-side scripting language like ASP. PHP scripts are executed on the server PHP supports.
PHP is a server scripting language, and a powerful tool for making dynamic and interactive Web pages. PHP is a widely-used, free, and efficient alternative.
1 Server Side scripting PHP. 2 What is PHP? PHP stands for PHP: Hypertext Preprocessor PHP is a server-side scripting language, like ASP PHP scripts are.
Introduction to PHP. PHP Origins Rasmus LerdorfRasmus Lerdorf (born Greenland, ed Canada) PHP originally abbreviation for ‘Personal Home Pages’, now ‘PHP.
CS242 SQL. What is SQL? SQL:  stands for Structured Query Language  allows you to access a database  is an ANSI standard computer language  can execute.
A pache M ySQL P hp Robert Mudge Reference:
PHP using MySQL Database for Web Development (part II)
Introduction to Dynamic Web Programming
BASIC PHP and MYSQL Edward S. Flores.
PHP Introduction.
ISC440: Web Programming 2 Server-side Scripting PHP 3
Web DB Programming: PHP
IntroductionToPHP Static vs. Dynamic websites
PHP: Database connection
Tutorial 6 PHP & MySQL Li Xu
Web Programming– UFCFB Lecture
Introduction to PHP.
SEEM 4540 Tutorial 4 Basic PHP based on w3Schools
Presentation transcript:

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 scripting language that is suited for Web development and can be embedded into HTML.  PHP scripts are executed on the server  PHP supports many different databases (MySQL, Informix, Oracle, Sybase, Solid, PostgreSQL, Generic ODBC, etc.)  PHP is an open source software (OSS), so its free  PHP files have a file extension of ".php", ".php3", or ".phtml"  PHP files are returned to the browser as plain HTML

Server Side o o PHP rules! ';?> o

Client Side   PHP rules! 

What do you need installed on your computer to use php?  A server that supports php. Some servers that support php are Apache(open source), IIS (Microsoft), and Oracle.  The latest version of PHP found at   You can test if php is installed and working with the following code.

Show php information   <?php  phpinfo();  ?> 

Some PHP syntax  A php statement always begins with.  php statements can be placed anywhere in the document.  Statements end with semicolon.

PHP variables  Variables start with $, example $var  Variables have the same syntax rules as other high level languages.  To concatenate two or more variables together, use the dot (.) operator:  Using the “\” right next to a variable name tells the server to print what directly follows and not to treat it as a label.

Sample Variables   <?php  $var_A = " Print \$var_A ";  $var_B = "To print a variable name instead  of what the variable is holding use the \  character.";  echo $var_B;  echo" ";  echo $var_A;  ?> 

PHP operators  Arithmetic Operators  +, -, /, *  Assignment Operators  =, +=, -=, *=, /=, %=  Comparison Operators  ==, !=, >, =, <=  Logical Operators  &&, ||, !  If – else statement  if (condition)  code to be executed  else  code to be executed  While  while { code to be executed; }  Do-while  do { code to be executed; } while (condition);  For  Foreach

PHP forms  Form is created with html.  Any html element you put in a form is available after a submit because php automatically makes element variables.  Examples: $_POST["first"],$_POST["last"  Notice that if you use post in the form header the variables are accessible with $_POST, if you use get the variables are accessible with $_GET.

Form   Your Id:   Your First name:   Your Last name:  <?php  echo "male: <input type = checkbox name = sex value  male>  Female: <input type = checkbox name= sex  value=female>  ?> 

Print form variables   You said your Id number was:   You said your First name was <?php echo  $_POST["first"]; ?>  You said you Last name was <?php echo  $_POST["last"]; ?>  You also said you are <?php echo  $_POST["sex"];?>  Your favorite color is <?php echo  $_POST["color"];?> 

Text File Read/Write   <?php  if (!($file=fopen("php_file.txt","r")))  exit("Can’t open file.");  while (!feof($file))  { $char=fgetc($file);  echo $char;  }  //$write = fputs($fp, “write hi”);  fclose($file);  ?> 

Using a database  The mysql_connect() function opens a link to a MySQL server on the specified host along with a username (root) and a password.  mysql_select_db() is used to tell my MySQL to use the specified database.  mysql_query()sends a line of SQL to the MySQL database identified in the connection for processing. The returned results are stored in $result.  mysql_result() is used to display the values of fields from our query.  %s indicates that the variable in the second half of the expression (e.g., mysql_result($result,0,"position")) should be treated as a string and printed.

Reading one field from each record in the database   <?php  $db = mysql_connect("localhost", "root","seth");  mysql_select_db("mydb",$db);  $result = mysql_query("SELECT * FROM employee",$db);  $count=mysql_numrows($result);  $i=0;  while ($i < $count)  {  printf("First Name: %s",  mysql_result($result,$i,"first"));  echo " ";  $i++;  }  mysql_close();  ?> 

Reading records one at a time   <?php  $db = mysql_connect("localhost", "root", "seth");  mysql_select_db("mydb",$db);  $result = mysql_query("SELECT * FROM employee",$db);  echo " \n";  echo " id First Name and Last Name \n";  while ($myrow = mysql_fetch_row($result))  {  printf(" %s %s %s \n",  $myrow[0], $myrow[1], $myrow[2]);  }  echo " \n";  ?> 

Inserting into a Database: form part   Your Id:  Your First name:  Your Last name: 

Insert into a MySQL database   <?php  $id = $_POST["id"];  $first = $_POST["first"];  $last = $_POST["last"];  $db = mysql_connect("localhost", "root","seth");  mysql_select_db("mydb",$db);  $result = mysql_query("SELECT * FROM employee",$db);  echo " \n";  echo " id First Name and Last Name \n";  while ($myrow = mysql_fetch_row($result))  {  printf(" %s %s %s \n",  $myrow[0], $myrow[1], $myrow[2]);  }  echo " \n";  $query = "INSERT INTO employee VALUES ('$id','$first','$last')";  mysql_query($query);  ?> 