SlideShare a Scribd company logo
SEG3560 Introduction to E-Commerce (Fall 2005)                            Tutorial – Php



                          SEG 3560 Introduction to E-Commerce
                                    Tutorial 4 – PHP
PHP Introduction
PHP (Hypertext Preprocessor), unlike Java Script which is a client-side HTML-embedded
script language, is a server-side HTML-embedded script language.

The functions of PHP are exactly the same as CGI. However, CGI is a stand-alone
component, while PHP is embedded inside HTML. More about PHP could be referred to the
official web site: http://www.php.net

PHP Basic
To declare a PHP section within an HTML document, just use the tag “<?” and “?>” and
change the file extension from “.html” (or “.htm”) to “.php”.

Example:




                             http://www.se.cuhk.edu.hk/~s3560_30/1.php

        <html>
        <head>
        <title>PHP Introduction</title>
        </head>

        <body>

        <?
         print("SEG 3560 Introduction to E-Commerce<br>");
         print("Tutorial 2<br>");
         print("A simple PHP demonstration<br>");

        echo "Hello World<br><br>";
        ?>

        </body>
        </html>




                                                                                 Page 1
SEG3560 Introduction to E-Commerce (Fall 2005)                                      Tutorial – Php



You could declare the PHP section in anywhere within the whole html document.

Example:




                             http://www.se.cuhk.edu.hk/~s3560_30/2.php

        <html>
        <head><title>PHP Introduction</title></head>

        <?
         print("<body link="#0000FF" vlink="#800080" alink="#FF0000">");
        ?>

        <?
        mail('xxx@xx.cuhk.edu.hk', 'Email Heading', 'Dear all, Testing only. By abc');
        ?>


        <p align="center"><img border="0" src="name_1.gif"
        width="478" height="86"></p>

        <?
         print("<p align="center"><font face="Arial">Click
                <a href="http://www.se.cuhk.edu.hk/~seg3560">here</a>
                to link to the ");
        ?>

        <b><font size="5" color="#FF0000">course web site</font></b>.</font> </p>

        </body>
        </html>




                                                                                           Page 2
SEG3560 Introduction to E-Commerce (Fall 2005)                               Tutorial – Php



PHP and Email

To send email using PHP automatically, use the mail function within PHP:
   mail(“email_address”, “heading”, “body”)

Example:
   <?
     mail(“abc@se.cuhk.edu.hk”, “Email Heading”, “Dear all, Testing only. By abc”)
   ?>




                                                                                     Page 3
SEG3560 Introduction to E-Commerce (Fall 2005)                              Tutorial – Php



Data Types and Variables
Every variable must begin with the symbol “$”. PHP support integer, double, string, and
array.

Example:




                             http://www.se.cuhk.edu.hk/~s3560_30/3.php

          <html>
          <head><title>PHP Introduction</title></head>

          <?
           $course="SEG".'3560';    // string
           $code=3450+110; // integer operation
           $num[0]=1;        // array
           $num[1]=2;        // array

           print("This course is $course $code<br>");
           print("This is tutorial $num[1]");
          ?>

          </body>
          </html>




                                                                                   Page 4
SEG3560 Introduction to E-Commerce (Fall 2005)                                       Tutorial – Php



Note that in PHP, you do not need to declare the data type. The data type of the variable will
be changed according to what you have stored in it.

Example:




                             http://www.se.cuhk.edu.hk/~s3560_30/4.php
        <html>
        <head>
        <title>PHP Introduction</title>
        </head>

        <?
         $variable = "SEG 3560";                 // initialize $variable to string
         print("The value is '$variable' (String)<br>");

         $variable = 10;                         // change it to integer
         print("The value is '$variable' (Integer)<br>");

         $variable = $variable + 10.1;          // change it to double
         print("The value is '$variable' (Double)<br>");

         $variable = "10.1 php" + $variable; // perform an operation
         print("The value is '$variable' (Double)<br>");
        ?>

        </body>
        </html>

However, it is a good practice that you do not change the data type of the variable frequently.




                                                                                            Page 5
SEG3560 Introduction to E-Commerce (Fall 2005)                               Tutorial – Php



PHP and Form

Consider the following form:




                           http://www.se.cuhk.edu.hk/~s3560_30/form.php
     <html>
     <head><title>Form</title></head>
     <body>
     <form method="POST"
      action="http://www.se.cuhk.edu.hk/~s3560_30/receive.php">

     <p>Username: <input type="text" name="USER" size="20"><br>
        Password: <input type="password" name="PSWD" size="20"></p>

     <p>I would like to learn:<br>
        <input type="checkbox" name="C1" value="Y">PHP
        <input type="checkbox" name="C2" value="Y">CGI
        <input type="checkbox" name="C3" value="Y">ASP
        <input type="checkbox" name="C4" value="Y">JAVA SCRIPT</p>

     <p>Sex: <input type="radio" value="B" name="SEX">M
         <input type="radio" value="G" name='SEX' checked >F

          Year of Study:
          <select size='1' name='YR'>
             <option>Year 1</option><option>Year 2</option><option>Year 3</option>
          </select></p>


                                                                                     Page 6
SEG3560 Introduction to E-Commerce (Fall 2005)                                Tutorial – Php



     <p>Comment about this course:<br>
        <textarea rows="3" name="COMMENT" cols="28"></textarea></p>

     <p><input type="submit" value="Submit" name="B1">
          <input type="reset" value="Reset" name="B2"></p>
     </form>
     </body>
     </html>




We could write the following PHP document to perform checking and displaying the result:




                                                                                     Page 7
SEG3560 Introduction to E-Commerce (Fall 2005)           Tutorial – Php



      <html>
      <head><title>Receive The Form</title><head>

      <body>
      <p><b><u><font face="Arial" color="#FF0000">
       You have enter the following information:
      </font></u></b></p>

      <p><font face="Arial">
        <font color="#0000FF"><b>Username: </b></font>
        <? print($_REQUEST['USER']); ?>
        <br>
        <font color="#0000FF"><b>Password: </b></font>
        <? print($_REQUEST['PSWD']); ?>
      </font></p>


      <p><font face="Arial">
        You are a
        <?
          if ($_REQUEST['SEX']=="B")
             print("boy");
          else
             print("girl");
        ?>
        studying in
        <? print($_REQUEST['YR']); ?>
      </font></p>

      <p><font face="Arial">
       <b>You want to learn: </b><br>
       <?
         if ($_REQUEST['C1']=="Y")
           print("PHP ");
         if ($_REQUEST['C2']=="Y")
           print("CGI ");
         if ($_REQUEST['C3']=="Y")
           print("ASP ");
         if ($_REQUEST['C4']=="Y")
           print("JAVA SCRIPT");
       ?>
      </font></p>

      <p><font face="Arial">
       <b>Your comment about the course is: </b><br>
       <?
         print($_REQUEST['COMMENT']);
       ?>
      </font></p>


      </body>
      </html>



                                                                Page 8
SEG3560 Introduction to E-Commerce (Fall 2005)                                         Tutorial – Php



PHP and Database Connection

In this tutorial, only the connection between PHP and oracle would be discussed. A revision
of SQL language could be found in the supplementary notes1 – SQL in this tutorial.
https://www-ssl.se.cuhk.edu.hk/intranet/tech/web_tech.html#PHP3


1. To initialize the connection:
   ora_logon (user_name, password) or die(‘Connection Error’);

    Example:
    Suppose we want to connect to the server SE with the username USER and password
    PSWD:
    <?
       /*Set Environment */
       putenv("ORACLE_SID=seora.se.cuhk.edu.hk");
       putenv("ORACLE_HOME=/usr/local/oracle");


         /*Opent the connection*/
         $handle = ora_logon('s3560_xx@seora','xxxxxxx') or die ("Connection error");
         $cursor = ora_open($handle);
    ?>

2. To send a query from Sybase through PHP:
   ora_parse (link , query);

    Example:
    Suppose we want to create the following table and input the data:

    first_db
       course (char)        student (int)
         'SEG3560'              150

    If we want to store information into oracle:
    <?
        ora_parse($cursor, "create table first_db (course char(10), student int)") ;
        ora_parse($cursor, "insert into first_db values('SEG3560', 150)");
    ?>




                                                                                              Page 9
SEG3560 Introduction to E-Commerce (Fall 2005)                        Tutorial – Php



3. To view the information retrieved from Sybase through PHP:
   ora_fetch (query_information)

    Example:
    <?
       ora_parse($cursor, "select * from first_db");
       ora_exec($cursor);
       ora_commit($handle);
       $numcols = 0;
       while(ora_fetch($cursor)){
              $numcols = ora_numcols($cursor);
              for($column=0; $column < $numcols; $column++){
                     $data = trim(ora_getcolumn($cursor, $column));
                     if($data =="") $data = "NULL";
                     echo"$datat";
              }
       }
    ?>


    Result:

    SEG3560 150




                                                                            Page 10
SEG3560 Introduction to E-Commerce (Fall 2005)                                      Tutorial – Php



Example:
  <html>
  <head>
  <title>PHP Introduction 123</title>
  </head>
  <?
  /*Set Environment */
  putenv("ORACLE_SID=seora.se.cuhk.edu.hk");
  putenv("ORACLE_HOME=/usr/local/oracle");

  /*Opent the connection*/
  $handle = ora_logon('s3560_30@seora','eFuoTyAp') or die ("Connection error");
  $cursor = ora_open($handle);
  ora_parse($cursor, "create table first_db (course char(10), student int)") or die("Sql 1
  error");
  ora_parse($cursor, "insert into first_db values('SEG3560', 150)") or die("Sql 2 error");
  /* Execute the sql*/
  ora_exec($cursor);
  ora_commit($handle);
  /*Close the connection*/
  ora_close($cursor);
  echo "Finished all the commands";
  ?>
  </body>
  </html>


    Create the table “first_db” and put an instance into the table.
    http://www.se.cuhk.edu.hk/~s3560_30/write_db.php
    Read the content in the table.
    http://www.se.cuhk.edu.hk/~s3560_30/read_db.php


    Be careful, the first link will work with sql error,




                                                                        ,
Think why?



                                                                                          Page 11
SEG3560 Introduction to E-Commerce (Fall 2005)                                             Tutorial – Php



         Tutorial 4 Supplementary Notes 1 – SQL

Example
Consider the following two tables, student_info and course_info:

student_info
 Name (char 20)            ID (int)         Department (char 3)     Supervisor (char 20)
     Agnes                00123456                SEM                    Prof. Cai
     Bonnie               00234567                 PSY                  Prof. Chan
      Clara               00345678                ECO                        -
      Doris               01234567                SEM                  Prof. Madan

course_info
  Course (char7)            Instructor (char 20)       Size (int)
    SEG3560                     Prof. Madan               98
    SEG3450                     Prof. Madan               84
    PSY3230                      Prof. Chan               25

Database Manipulation:
1. Create a table:
   create table table_name (attribute1 data_type, attribute2 data_type, …)

    Example:
    create the table course_info:
    create table course_info (course char(7), instructor char(20), size int)

2. Remove a table:
   drop table table_name

    Example:
    remove the table course_info:
    drop table course_info

Basic Database Access
1. Select Operation:
   select attibute1, attribute2, … from table1, table2, … where condition

    Example:
    Select all courses from the table course_info:
    select course from course_info

    Select all courses from the table course_info where the class size is greater then 50:
    select course from course_info where size>50

    Select all courses taught by Professor Madan:
    select course from course_info where instructor=’Prof. Madan’

    Select all courses offered by SEG:
    select course from course_info where course like ‘SEG%’

                                                                                                 Page 12
SEG3560 Introduction to E-Commerce (Fall 2005)                                    Tutorial – Php



    Select all students whose supervisor has taught at least one course:
    select student_info.name from student_info, course_info
    where student_info.supervisor=course_info.supervisor.

    Select all records from the table student_info
    select * from student_info

2. Insert Operation
   insert into table_name values (value1, value2, …)
                      OR
   insert into table_name values (attribute1=value1, attribute2=value2, …)

    Example:
    Insert the course SEG5010 taught by Professor Yu with class size 25 in the table:
    insert into course_info values (‘SEG5010’, ‘Prof. Yu’, 25)

    Insert the student Eddie (01345678) studying in ECO:
    insert into student_info values (name=‘Eddie’, id=01345678, department=‘ECO’)

3. Delete Operation
   delete from table_name where condition

    Example:
    Delete all records from the table course_info:
    delete from course_info

    Delete all students who are studying in ECO:
    delete from student_info where department=’ECO’

4. Update Operation:
   update table_name set attribute1=value1, attrubute2=value2… where condition

    Example:
    Change the class size of all classes to 40:
    update course_info set size=40

    Change the class size of the course PSY3230 to 40:
    update course_info set size=40 where course=’PSY3230’

Note:
Different databases support different data types. However, some data types are supported by
all databases, such as: integer (int), real number (real) and character (char (n)).




                                                                                        Page 13
SEG3560 Introduction to E-Commerce (Fall 2005)                                      Tutorial – Php



             Tutorial 4 Supplementary Note 2 – Web Page and Sybase

Creating web pages within SE department
1. Create a directory named /public_html under the root directory of your Unix account.

2. Upload or create all of the necessary files and directories to the directory /public_html

3. Change the access mode to all of the files and directories (as well as the /public_html) to
   755 (owner—full control of all the file/directory; group and public—only could read or
   execute the file/directory).

    If you are under Unix environment, simply type:
        Chmod –R 755 /public_html*
    in your root directory

4. You could view your web pages using the following URL:
      www.se.cuhk.edu.hk/~XXX
   where XXX is your account name.




                                                                                          Page 14

More Related Content

What's hot

Lca05
Lca05Lca05
Lca05
Sateesh Patil
 
PHP Security
PHP SecurityPHP Security
PHP Security
manugoel2003
 
Forms, Getting Your Money's Worth
Forms, Getting Your Money's WorthForms, Getting Your Money's Worth
Forms, Getting Your Money's Worth
Alex Gaynor
 
Php Basic Security
Php Basic SecurityPhp Basic Security
Php Basic Security
mussawir20
 
Php tutorial
Php tutorialPhp tutorial
What's new in Rails 2?
What's new in Rails 2?What's new in Rails 2?
What's new in Rails 2?
brynary
 
Cena-DTA PHP Conference 2011 Slides
Cena-DTA PHP Conference 2011 SlidesCena-DTA PHP Conference 2011 Slides
Cena-DTA PHP Conference 2011 Slides
Asao Kamei
 
Spstc2011 managed metadata real world
Spstc2011 managed metadata real worldSpstc2011 managed metadata real world
Spstc2011 managed metadata real world
Atul Chhoda
 
Week 1 (v3)
Week 1 (v3)Week 1 (v3)
Week 1 (v3)
Will Gaybrick
 
Week 1
Week 1Week 1
Week 1
Will Gaybrick
 
Week 1
Week 1Week 1
Week 1
Will Gaybrick
 
Stop the noise! - Introduction to the JSON:API specification in Drupal
Stop the noise! - Introduction to the JSON:API specification in DrupalStop the noise! - Introduction to the JSON:API specification in Drupal
Stop the noise! - Introduction to the JSON:API specification in Drupal
BjĂśrn Brala
 
Sperimentazioni di Tecnologie e Comunicazioni Multimediali: Lezione 5
Sperimentazioni di Tecnologie e Comunicazioni Multimediali: Lezione 5Sperimentazioni di Tecnologie e Comunicazioni Multimediali: Lezione 5
Sperimentazioni di Tecnologie e Comunicazioni Multimediali: Lezione 5
Salvatore Iaconesi
 
Introduction to CodeIgniter (RefreshAugusta, 20 May 2009)
Introduction to CodeIgniter (RefreshAugusta, 20 May 2009)Introduction to CodeIgniter (RefreshAugusta, 20 May 2009)
Introduction to CodeIgniter (RefreshAugusta, 20 May 2009)
Michael Wales
 
jQuery from the very beginning
jQuery from the very beginningjQuery from the very beginning
jQuery from the very beginning
Anis Ahmad
 

What's hot (15)

Lca05
Lca05Lca05
Lca05
 
PHP Security
PHP SecurityPHP Security
PHP Security
 
Forms, Getting Your Money's Worth
Forms, Getting Your Money's WorthForms, Getting Your Money's Worth
Forms, Getting Your Money's Worth
 
Php Basic Security
Php Basic SecurityPhp Basic Security
Php Basic Security
 
Php tutorial
Php tutorialPhp tutorial
Php tutorial
 
What's new in Rails 2?
What's new in Rails 2?What's new in Rails 2?
What's new in Rails 2?
 
Cena-DTA PHP Conference 2011 Slides
Cena-DTA PHP Conference 2011 SlidesCena-DTA PHP Conference 2011 Slides
Cena-DTA PHP Conference 2011 Slides
 
Spstc2011 managed metadata real world
Spstc2011 managed metadata real worldSpstc2011 managed metadata real world
Spstc2011 managed metadata real world
 
Week 1 (v3)
Week 1 (v3)Week 1 (v3)
Week 1 (v3)
 
Week 1
Week 1Week 1
Week 1
 
Week 1
Week 1Week 1
Week 1
 
Stop the noise! - Introduction to the JSON:API specification in Drupal
Stop the noise! - Introduction to the JSON:API specification in DrupalStop the noise! - Introduction to the JSON:API specification in Drupal
Stop the noise! - Introduction to the JSON:API specification in Drupal
 
Sperimentazioni di Tecnologie e Comunicazioni Multimediali: Lezione 5
Sperimentazioni di Tecnologie e Comunicazioni Multimediali: Lezione 5Sperimentazioni di Tecnologie e Comunicazioni Multimediali: Lezione 5
Sperimentazioni di Tecnologie e Comunicazioni Multimediali: Lezione 5
 
Introduction to CodeIgniter (RefreshAugusta, 20 May 2009)
Introduction to CodeIgniter (RefreshAugusta, 20 May 2009)Introduction to CodeIgniter (RefreshAugusta, 20 May 2009)
Introduction to CodeIgniter (RefreshAugusta, 20 May 2009)
 
jQuery from the very beginning
jQuery from the very beginningjQuery from the very beginning
jQuery from the very beginning
 

Viewers also liked

Sport and health policies
Sport and health policiesSport and health policies
quicktip_scanphotoshop
quicktip_scanphotoshopquicktip_scanphotoshop
quicktip_scanphotoshop
tutorialsruby
 
Transformers Episode 16 Omega Supreme
Transformers Episode 16 Omega SupremeTransformers Episode 16 Omega Supreme
Transformers Episode 16 Omega Supreme
Ryan Sadler
 
LatexTutorial
LatexTutorialLatexTutorial
LatexTutorial
tutorialsruby
 
1proyec
1proyec1proyec
Owi school heads presentation
Owi school heads presentationOwi school heads presentation
Owi school heads presentation
Stephen Chiunjira
 
Day_1__Adjusting_images
Day_1__Adjusting_imagesDay_1__Adjusting_images
Day_1__Adjusting_images
tutorialsruby
 
LCI2009-Tutorial
LCI2009-TutorialLCI2009-Tutorial
LCI2009-Tutorial
tutorialsruby
 
backend
backendbackend
backend
tutorialsruby
 
First Magazine Analysis
First Magazine AnalysisFirst Magazine Analysis
First Magazine Analysis
guest0f911b
 
nukesop
nukesopnukesop
nukesop
tutorialsruby
 
Bunding Or Binding Dr. Shriniwas Kashalikar
Bunding Or Binding  Dr. Shriniwas KashalikarBunding Or Binding  Dr. Shriniwas Kashalikar
Bunding Or Binding Dr. Shriniwas Kashalikar
drsolapurkar
 
hwk1
hwk1hwk1
introduction
introductionintroduction
introduction
tutorialsruby
 
cs3157-summer06-lab1
cs3157-summer06-lab1cs3157-summer06-lab1
cs3157-summer06-lab1
tutorialsruby
 
Fall_2008_CS601_W1_Tyngsboro
Fall_2008_CS601_W1_TyngsboroFall_2008_CS601_W1_Tyngsboro
Fall_2008_CS601_W1_Tyngsboro
tutorialsruby
 
CURRICULUM VITAE
CURRICULUM VITAECURRICULUM VITAE
CURRICULUM VITAE
Anand Patel
 
20 Factsand34 Examples About Social Media Oct09 Christian Palau
20 Factsand34 Examples About Social Media Oct09 Christian Palau20 Factsand34 Examples About Social Media Oct09 Christian Palau
20 Factsand34 Examples About Social Media Oct09 Christian Palau
fotocasa
 
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa0602690047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
tutorialsruby
 
mobility_whtppr_php
mobility_whtppr_phpmobility_whtppr_php
mobility_whtppr_php
tutorialsruby
 

Viewers also liked (20)

Sport and health policies
Sport and health policiesSport and health policies
Sport and health policies
 
quicktip_scanphotoshop
quicktip_scanphotoshopquicktip_scanphotoshop
quicktip_scanphotoshop
 
Transformers Episode 16 Omega Supreme
Transformers Episode 16 Omega SupremeTransformers Episode 16 Omega Supreme
Transformers Episode 16 Omega Supreme
 
LatexTutorial
LatexTutorialLatexTutorial
LatexTutorial
 
1proyec
1proyec1proyec
1proyec
 
Owi school heads presentation
Owi school heads presentationOwi school heads presentation
Owi school heads presentation
 
Day_1__Adjusting_images
Day_1__Adjusting_imagesDay_1__Adjusting_images
Day_1__Adjusting_images
 
LCI2009-Tutorial
LCI2009-TutorialLCI2009-Tutorial
LCI2009-Tutorial
 
backend
backendbackend
backend
 
First Magazine Analysis
First Magazine AnalysisFirst Magazine Analysis
First Magazine Analysis
 
nukesop
nukesopnukesop
nukesop
 
Bunding Or Binding Dr. Shriniwas Kashalikar
Bunding Or Binding  Dr. Shriniwas KashalikarBunding Or Binding  Dr. Shriniwas Kashalikar
Bunding Or Binding Dr. Shriniwas Kashalikar
 
hwk1
hwk1hwk1
hwk1
 
introduction
introductionintroduction
introduction
 
cs3157-summer06-lab1
cs3157-summer06-lab1cs3157-summer06-lab1
cs3157-summer06-lab1
 
Fall_2008_CS601_W1_Tyngsboro
Fall_2008_CS601_W1_TyngsboroFall_2008_CS601_W1_Tyngsboro
Fall_2008_CS601_W1_Tyngsboro
 
CURRICULUM VITAE
CURRICULUM VITAECURRICULUM VITAE
CURRICULUM VITAE
 
20 Factsand34 Examples About Social Media Oct09 Christian Palau
20 Factsand34 Examples About Social Media Oct09 Christian Palau20 Factsand34 Examples About Social Media Oct09 Christian Palau
20 Factsand34 Examples About Social Media Oct09 Christian Palau
 
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa0602690047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
 
mobility_whtppr_php
mobility_whtppr_phpmobility_whtppr_php
mobility_whtppr_php
 

Similar to Tutorial_4_PHP

Introduction to PHP
Introduction to PHPIntroduction to PHP
Introduction to PHP
Collaboration Technologies
 
Login and Registration form using oop in php
Login and Registration form using oop in phpLogin and Registration form using oop in php
Login and Registration form using oop in php
herat university
 
Introducation to php for beginners
Introducation to php for beginners Introducation to php for beginners
Introducation to php for beginners
musrath mohammad
 
Php with my sql
Php with my sqlPhp with my sql
Php with my sql
husnara mohammad
 
GettingStartedWithPHP
GettingStartedWithPHPGettingStartedWithPHP
GettingStartedWithPHP
Nat Weerawan
 
SULTHAN's - PHP MySQL programs
SULTHAN's - PHP MySQL programsSULTHAN's - PHP MySQL programs
SULTHAN's - PHP MySQL programs
SULTHAN BASHA
 
PHP and MySQL : Server Side Scripting For Web Development
PHP and MySQL : Server Side Scripting For Web DevelopmentPHP and MySQL : Server Side Scripting For Web Development
PHP and MySQL : Server Side Scripting For Web Development
Edureka!
 
PHP and MySQL.ppt
PHP and MySQL.pptPHP and MySQL.ppt
PHP and MySQL.ppt
ROGELIOVILLARUBIA
 
Geek Moot '09 -- Smarty 101
Geek Moot '09 -- Smarty 101Geek Moot '09 -- Smarty 101
Geek Moot '09 -- Smarty 101
Ted Kulp
 
Exploring Symfony's Code
Exploring Symfony's CodeExploring Symfony's Code
Exploring Symfony's Code
Wildan Maulana
 
Php mysql ppt
Php mysql pptPhp mysql ppt
PHP-Part4
PHP-Part4PHP-Part4
PHP-Part4
Ahmed Saihood
 
PHP-04-Forms.ppt
PHP-04-Forms.pptPHP-04-Forms.ppt
PHP-04-Forms.ppt
NatureLifearabhi
 
PHP Arrays - indexed and associative array.
PHP Arrays - indexed and associative array. PHP Arrays - indexed and associative array.
PHP Arrays - indexed and associative array.
wahidullah mudaser
 
Php Tutorial
Php TutorialPhp Tutorial
Quick beginner to Lower-Advanced guide/tutorial in PHP
Quick beginner to Lower-Advanced guide/tutorial in PHPQuick beginner to Lower-Advanced guide/tutorial in PHP
Quick beginner to Lower-Advanced guide/tutorial in PHP
Sanju Sony Kurian
 
&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />
tutorialsruby
 
Blog Hacks 2011
Blog Hacks 2011Blog Hacks 2011
Blog Hacks 2011
Yusuke Wada
 
Intro to php
Intro to phpIntro to php
Intro to php
Sp Singh
 
php-mysql-tutorial-part-3
php-mysql-tutorial-part-3php-mysql-tutorial-part-3
php-mysql-tutorial-part-3
tutorialsruby
 

Similar to Tutorial_4_PHP (20)

Introduction to PHP
Introduction to PHPIntroduction to PHP
Introduction to PHP
 
Login and Registration form using oop in php
Login and Registration form using oop in phpLogin and Registration form using oop in php
Login and Registration form using oop in php
 
Introducation to php for beginners
Introducation to php for beginners Introducation to php for beginners
Introducation to php for beginners
 
Php with my sql
Php with my sqlPhp with my sql
Php with my sql
 
GettingStartedWithPHP
GettingStartedWithPHPGettingStartedWithPHP
GettingStartedWithPHP
 
SULTHAN's - PHP MySQL programs
SULTHAN's - PHP MySQL programsSULTHAN's - PHP MySQL programs
SULTHAN's - PHP MySQL programs
 
PHP and MySQL : Server Side Scripting For Web Development
PHP and MySQL : Server Side Scripting For Web DevelopmentPHP and MySQL : Server Side Scripting For Web Development
PHP and MySQL : Server Side Scripting For Web Development
 
PHP and MySQL.ppt
PHP and MySQL.pptPHP and MySQL.ppt
PHP and MySQL.ppt
 
Geek Moot '09 -- Smarty 101
Geek Moot '09 -- Smarty 101Geek Moot '09 -- Smarty 101
Geek Moot '09 -- Smarty 101
 
Exploring Symfony's Code
Exploring Symfony's CodeExploring Symfony's Code
Exploring Symfony's Code
 
Php mysql ppt
Php mysql pptPhp mysql ppt
Php mysql ppt
 
PHP-Part4
PHP-Part4PHP-Part4
PHP-Part4
 
PHP-04-Forms.ppt
PHP-04-Forms.pptPHP-04-Forms.ppt
PHP-04-Forms.ppt
 
PHP Arrays - indexed and associative array.
PHP Arrays - indexed and associative array. PHP Arrays - indexed and associative array.
PHP Arrays - indexed and associative array.
 
Php Tutorial
Php TutorialPhp Tutorial
Php Tutorial
 
Quick beginner to Lower-Advanced guide/tutorial in PHP
Quick beginner to Lower-Advanced guide/tutorial in PHPQuick beginner to Lower-Advanced guide/tutorial in PHP
Quick beginner to Lower-Advanced guide/tutorial in PHP
 
&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />
 
Blog Hacks 2011
Blog Hacks 2011Blog Hacks 2011
Blog Hacks 2011
 
Intro to php
Intro to phpIntro to php
Intro to php
 
php-mysql-tutorial-part-3
php-mysql-tutorial-part-3php-mysql-tutorial-part-3
php-mysql-tutorial-part-3
 

More from tutorialsruby

&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />
tutorialsruby
 
TopStyle Help &amp; &lt;b>Tutorial&lt;/b>
TopStyle Help &amp; &lt;b>Tutorial&lt;/b>TopStyle Help &amp; &lt;b>Tutorial&lt;/b>
TopStyle Help &amp; &lt;b>Tutorial&lt;/b>
tutorialsruby
 
The Art Institute of Atlanta IMD 210 Fundamentals of Scripting &lt;b>...&lt;/b>
The Art Institute of Atlanta IMD 210 Fundamentals of Scripting &lt;b>...&lt;/b>The Art Institute of Atlanta IMD 210 Fundamentals of Scripting &lt;b>...&lt;/b>
The Art Institute of Atlanta IMD 210 Fundamentals of Scripting &lt;b>...&lt;/b>
tutorialsruby
 
&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />
tutorialsruby
 
&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />
tutorialsruby
 
Standardization and Knowledge Transfer – INS0
Standardization and Knowledge Transfer – INS0Standardization and Knowledge Transfer – INS0
Standardization and Knowledge Transfer – INS0
tutorialsruby
 
xhtml_basics
xhtml_basicsxhtml_basics
xhtml_basics
tutorialsruby
 
xhtml_basics
xhtml_basicsxhtml_basics
xhtml_basics
tutorialsruby
 
xhtml-documentation
xhtml-documentationxhtml-documentation
xhtml-documentation
tutorialsruby
 
xhtml-documentation
xhtml-documentationxhtml-documentation
xhtml-documentation
tutorialsruby
 
CSS
CSSCSS
CSS
CSSCSS
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa0602690047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
tutorialsruby
 
HowTo_CSS
HowTo_CSSHowTo_CSS
HowTo_CSS
tutorialsruby
 
HowTo_CSS
HowTo_CSSHowTo_CSS
HowTo_CSS
tutorialsruby
 
BloggingWithStyle_2008
BloggingWithStyle_2008BloggingWithStyle_2008
BloggingWithStyle_2008
tutorialsruby
 
BloggingWithStyle_2008
BloggingWithStyle_2008BloggingWithStyle_2008
BloggingWithStyle_2008
tutorialsruby
 
cascadingstylesheets
cascadingstylesheetscascadingstylesheets
cascadingstylesheets
tutorialsruby
 
cascadingstylesheets
cascadingstylesheetscascadingstylesheets
cascadingstylesheets
tutorialsruby
 
Winter%200405%20-%20Advanced%20Javascript
Winter%200405%20-%20Advanced%20JavascriptWinter%200405%20-%20Advanced%20Javascript
Winter%200405%20-%20Advanced%20Javascript
tutorialsruby
 

More from tutorialsruby (20)

&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />
 
TopStyle Help &amp; &lt;b>Tutorial&lt;/b>
TopStyle Help &amp; &lt;b>Tutorial&lt;/b>TopStyle Help &amp; &lt;b>Tutorial&lt;/b>
TopStyle Help &amp; &lt;b>Tutorial&lt;/b>
 
The Art Institute of Atlanta IMD 210 Fundamentals of Scripting &lt;b>...&lt;/b>
The Art Institute of Atlanta IMD 210 Fundamentals of Scripting &lt;b>...&lt;/b>The Art Institute of Atlanta IMD 210 Fundamentals of Scripting &lt;b>...&lt;/b>
The Art Institute of Atlanta IMD 210 Fundamentals of Scripting &lt;b>...&lt;/b>
 
&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />
 
&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />
 
Standardization and Knowledge Transfer – INS0
Standardization and Knowledge Transfer – INS0Standardization and Knowledge Transfer – INS0
Standardization and Knowledge Transfer – INS0
 
xhtml_basics
xhtml_basicsxhtml_basics
xhtml_basics
 
xhtml_basics
xhtml_basicsxhtml_basics
xhtml_basics
 
xhtml-documentation
xhtml-documentationxhtml-documentation
xhtml-documentation
 
xhtml-documentation
xhtml-documentationxhtml-documentation
xhtml-documentation
 
CSS
CSSCSS
CSS
 
CSS
CSSCSS
CSS
 
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa0602690047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
 
HowTo_CSS
HowTo_CSSHowTo_CSS
HowTo_CSS
 
HowTo_CSS
HowTo_CSSHowTo_CSS
HowTo_CSS
 
BloggingWithStyle_2008
BloggingWithStyle_2008BloggingWithStyle_2008
BloggingWithStyle_2008
 
BloggingWithStyle_2008
BloggingWithStyle_2008BloggingWithStyle_2008
BloggingWithStyle_2008
 
cascadingstylesheets
cascadingstylesheetscascadingstylesheets
cascadingstylesheets
 
cascadingstylesheets
cascadingstylesheetscascadingstylesheets
cascadingstylesheets
 
Winter%200405%20-%20Advanced%20Javascript
Winter%200405%20-%20Advanced%20JavascriptWinter%200405%20-%20Advanced%20Javascript
Winter%200405%20-%20Advanced%20Javascript
 

Recently uploaded

Biomedical Knowledge Graphs for Data Scientists and Bioinformaticians
Biomedical Knowledge Graphs for Data Scientists and BioinformaticiansBiomedical Knowledge Graphs for Data Scientists and Bioinformaticians
Biomedical Knowledge Graphs for Data Scientists and Bioinformaticians
Neo4j
 
Apps Break Data
Apps Break DataApps Break Data
Apps Break Data
Ivo Velitchkov
 
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development ProvidersYour One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
akankshawande
 
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
Alex Pruden
 
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
saastr
 
"Frontline Battles with DDoS: Best practices and Lessons Learned", Igor Ivaniuk
"Frontline Battles with DDoS: Best practices and Lessons Learned",  Igor Ivaniuk"Frontline Battles with DDoS: Best practices and Lessons Learned",  Igor Ivaniuk
"Frontline Battles with DDoS: Best practices and Lessons Learned", Igor Ivaniuk
Fwdays
 
Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)
Jakub Marek
 
Leveraging the Graph for Clinical Trials and Standards
Leveraging the Graph for Clinical Trials and StandardsLeveraging the Graph for Clinical Trials and Standards
Leveraging the Graph for Clinical Trials and Standards
Neo4j
 
Energy Efficient Video Encoding for Cloud and Edge Computing Instances
Energy Efficient Video Encoding for Cloud and Edge Computing InstancesEnergy Efficient Video Encoding for Cloud and Edge Computing Instances
Energy Efficient Video Encoding for Cloud and Edge Computing Instances
Alpen-Adria-Universität
 
Principle of conventional tomography-Bibash Shahi ppt..pptx
Principle of conventional tomography-Bibash Shahi ppt..pptxPrinciple of conventional tomography-Bibash Shahi ppt..pptx
Principle of conventional tomography-Bibash Shahi ppt..pptx
BibashShahi
 
Essentials of Automations: Exploring Attributes & Automation Parameters
Essentials of Automations: Exploring Attributes & Automation ParametersEssentials of Automations: Exploring Attributes & Automation Parameters
Essentials of Automations: Exploring Attributes & Automation Parameters
Safe Software
 
[OReilly Superstream] Occupy the Space: A grassroots guide to engineering (an...
[OReilly Superstream] Occupy the Space: A grassroots guide to engineering (an...[OReilly Superstream] Occupy the Space: A grassroots guide to engineering (an...
[OReilly Superstream] Occupy the Space: A grassroots guide to engineering (an...
Jason Yip
 
Y-Combinator seed pitch deck template PP
Y-Combinator seed pitch deck template PPY-Combinator seed pitch deck template PP
Y-Combinator seed pitch deck template PP
c5vrf27qcz
 
Astute Business Solutions | Oracle Cloud Partner |
Astute Business Solutions | Oracle Cloud Partner |Astute Business Solutions | Oracle Cloud Partner |
Astute Business Solutions | Oracle Cloud Partner |
AstuteBusiness
 
Taking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdfTaking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdf
ssuserfac0301
 
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdfMonitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Tosin Akinosho
 
AppSec PNW: Android and iOS Application Security with MobSF
AppSec PNW: Android and iOS Application Security with MobSFAppSec PNW: Android and iOS Application Security with MobSF
AppSec PNW: Android and iOS Application Security with MobSF
Ajin Abraham
 
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success StoryDriving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Safe Software
 
“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...
“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...
“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...
Edge AI and Vision Alliance
 

Recently uploaded (20)

Biomedical Knowledge Graphs for Data Scientists and Bioinformaticians
Biomedical Knowledge Graphs for Data Scientists and BioinformaticiansBiomedical Knowledge Graphs for Data Scientists and Bioinformaticians
Biomedical Knowledge Graphs for Data Scientists and Bioinformaticians
 
Apps Break Data
Apps Break DataApps Break Data
Apps Break Data
 
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development ProvidersYour One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
 
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
 
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
 
"Frontline Battles with DDoS: Best practices and Lessons Learned", Igor Ivaniuk
"Frontline Battles with DDoS: Best practices and Lessons Learned",  Igor Ivaniuk"Frontline Battles with DDoS: Best practices and Lessons Learned",  Igor Ivaniuk
"Frontline Battles with DDoS: Best practices and Lessons Learned", Igor Ivaniuk
 
Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)
 
Leveraging the Graph for Clinical Trials and Standards
Leveraging the Graph for Clinical Trials and StandardsLeveraging the Graph for Clinical Trials and Standards
Leveraging the Graph for Clinical Trials and Standards
 
Artificial Intelligence and Electronic Warfare
Artificial Intelligence and Electronic WarfareArtificial Intelligence and Electronic Warfare
Artificial Intelligence and Electronic Warfare
 
Energy Efficient Video Encoding for Cloud and Edge Computing Instances
Energy Efficient Video Encoding for Cloud and Edge Computing InstancesEnergy Efficient Video Encoding for Cloud and Edge Computing Instances
Energy Efficient Video Encoding for Cloud and Edge Computing Instances
 
Principle of conventional tomography-Bibash Shahi ppt..pptx
Principle of conventional tomography-Bibash Shahi ppt..pptxPrinciple of conventional tomography-Bibash Shahi ppt..pptx
Principle of conventional tomography-Bibash Shahi ppt..pptx
 
Essentials of Automations: Exploring Attributes & Automation Parameters
Essentials of Automations: Exploring Attributes & Automation ParametersEssentials of Automations: Exploring Attributes & Automation Parameters
Essentials of Automations: Exploring Attributes & Automation Parameters
 
[OReilly Superstream] Occupy the Space: A grassroots guide to engineering (an...
[OReilly Superstream] Occupy the Space: A grassroots guide to engineering (an...[OReilly Superstream] Occupy the Space: A grassroots guide to engineering (an...
[OReilly Superstream] Occupy the Space: A grassroots guide to engineering (an...
 
Y-Combinator seed pitch deck template PP
Y-Combinator seed pitch deck template PPY-Combinator seed pitch deck template PP
Y-Combinator seed pitch deck template PP
 
Astute Business Solutions | Oracle Cloud Partner |
Astute Business Solutions | Oracle Cloud Partner |Astute Business Solutions | Oracle Cloud Partner |
Astute Business Solutions | Oracle Cloud Partner |
 
Taking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdfTaking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdf
 
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdfMonitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdf
 
AppSec PNW: Android and iOS Application Security with MobSF
AppSec PNW: Android and iOS Application Security with MobSFAppSec PNW: Android and iOS Application Security with MobSF
AppSec PNW: Android and iOS Application Security with MobSF
 
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success StoryDriving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success Story
 
“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...
“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...
“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...
 

Tutorial_4_PHP

  • 1. SEG3560 Introduction to E-Commerce (Fall 2005) Tutorial – Php SEG 3560 Introduction to E-Commerce Tutorial 4 – PHP PHP Introduction PHP (Hypertext Preprocessor), unlike Java Script which is a client-side HTML-embedded script language, is a server-side HTML-embedded script language. The functions of PHP are exactly the same as CGI. However, CGI is a stand-alone component, while PHP is embedded inside HTML. More about PHP could be referred to the official web site: http://www.php.net PHP Basic To declare a PHP section within an HTML document, just use the tag “<?” and “?>” and change the file extension from “.html” (or “.htm”) to “.php”. Example: http://www.se.cuhk.edu.hk/~s3560_30/1.php <html> <head> <title>PHP Introduction</title> </head> <body> <? print("SEG 3560 Introduction to E-Commerce<br>"); print("Tutorial 2<br>"); print("A simple PHP demonstration<br>"); echo "Hello World<br><br>"; ?> </body> </html> Page 1
  • 2. SEG3560 Introduction to E-Commerce (Fall 2005) Tutorial – Php You could declare the PHP section in anywhere within the whole html document. Example: http://www.se.cuhk.edu.hk/~s3560_30/2.php <html> <head><title>PHP Introduction</title></head> <? print("<body link="#0000FF" vlink="#800080" alink="#FF0000">"); ?> <? mail('xxx@xx.cuhk.edu.hk', 'Email Heading', 'Dear all, Testing only. By abc'); ?> <p align="center"><img border="0" src="name_1.gif" width="478" height="86"></p> <? print("<p align="center"><font face="Arial">Click <a href="http://www.se.cuhk.edu.hk/~seg3560">here</a> to link to the "); ?> <b><font size="5" color="#FF0000">course web site</font></b>.</font> </p> </body> </html> Page 2
  • 3. SEG3560 Introduction to E-Commerce (Fall 2005) Tutorial – Php PHP and Email To send email using PHP automatically, use the mail function within PHP: mail(“email_address”, “heading”, “body”) Example: <? mail(“abc@se.cuhk.edu.hk”, “Email Heading”, “Dear all, Testing only. By abc”) ?> Page 3
  • 4. SEG3560 Introduction to E-Commerce (Fall 2005) Tutorial – Php Data Types and Variables Every variable must begin with the symbol “$”. PHP support integer, double, string, and array. Example: http://www.se.cuhk.edu.hk/~s3560_30/3.php <html> <head><title>PHP Introduction</title></head> <? $course="SEG".'3560'; // string $code=3450+110; // integer operation $num[0]=1; // array $num[1]=2; // array print("This course is $course $code<br>"); print("This is tutorial $num[1]"); ?> </body> </html> Page 4
  • 5. SEG3560 Introduction to E-Commerce (Fall 2005) Tutorial – Php Note that in PHP, you do not need to declare the data type. The data type of the variable will be changed according to what you have stored in it. Example: http://www.se.cuhk.edu.hk/~s3560_30/4.php <html> <head> <title>PHP Introduction</title> </head> <? $variable = "SEG 3560"; // initialize $variable to string print("The value is '$variable' (String)<br>"); $variable = 10; // change it to integer print("The value is '$variable' (Integer)<br>"); $variable = $variable + 10.1; // change it to double print("The value is '$variable' (Double)<br>"); $variable = "10.1 php" + $variable; // perform an operation print("The value is '$variable' (Double)<br>"); ?> </body> </html> However, it is a good practice that you do not change the data type of the variable frequently. Page 5
  • 6. SEG3560 Introduction to E-Commerce (Fall 2005) Tutorial – Php PHP and Form Consider the following form: http://www.se.cuhk.edu.hk/~s3560_30/form.php <html> <head><title>Form</title></head> <body> <form method="POST" action="http://www.se.cuhk.edu.hk/~s3560_30/receive.php"> <p>Username: <input type="text" name="USER" size="20"><br> Password: <input type="password" name="PSWD" size="20"></p> <p>I would like to learn:<br> <input type="checkbox" name="C1" value="Y">PHP <input type="checkbox" name="C2" value="Y">CGI <input type="checkbox" name="C3" value="Y">ASP <input type="checkbox" name="C4" value="Y">JAVA SCRIPT</p> <p>Sex: <input type="radio" value="B" name="SEX">M <input type="radio" value="G" name='SEX' checked >F Year of Study: <select size='1' name='YR'> <option>Year 1</option><option>Year 2</option><option>Year 3</option> </select></p> Page 6
  • 7. SEG3560 Introduction to E-Commerce (Fall 2005) Tutorial – Php <p>Comment about this course:<br> <textarea rows="3" name="COMMENT" cols="28"></textarea></p> <p><input type="submit" value="Submit" name="B1"> <input type="reset" value="Reset" name="B2"></p> </form> </body> </html> We could write the following PHP document to perform checking and displaying the result: Page 7
  • 8. SEG3560 Introduction to E-Commerce (Fall 2005) Tutorial – Php <html> <head><title>Receive The Form</title><head> <body> <p><b><u><font face="Arial" color="#FF0000"> You have enter the following information: </font></u></b></p> <p><font face="Arial"> <font color="#0000FF"><b>Username: </b></font> <? print($_REQUEST['USER']); ?> <br> <font color="#0000FF"><b>Password: </b></font> <? print($_REQUEST['PSWD']); ?> </font></p> <p><font face="Arial"> You are a <? if ($_REQUEST['SEX']=="B") print("boy"); else print("girl"); ?> studying in <? print($_REQUEST['YR']); ?> </font></p> <p><font face="Arial"> <b>You want to learn: </b><br> <? if ($_REQUEST['C1']=="Y") print("PHP "); if ($_REQUEST['C2']=="Y") print("CGI "); if ($_REQUEST['C3']=="Y") print("ASP "); if ($_REQUEST['C4']=="Y") print("JAVA SCRIPT"); ?> </font></p> <p><font face="Arial"> <b>Your comment about the course is: </b><br> <? print($_REQUEST['COMMENT']); ?> </font></p> </body> </html> Page 8
  • 9. SEG3560 Introduction to E-Commerce (Fall 2005) Tutorial – Php PHP and Database Connection In this tutorial, only the connection between PHP and oracle would be discussed. A revision of SQL language could be found in the supplementary notes1 – SQL in this tutorial. https://www-ssl.se.cuhk.edu.hk/intranet/tech/web_tech.html#PHP3 1. To initialize the connection: ora_logon (user_name, password) or die(‘Connection Error’); Example: Suppose we want to connect to the server SE with the username USER and password PSWD: <? /*Set Environment */ putenv("ORACLE_SID=seora.se.cuhk.edu.hk"); putenv("ORACLE_HOME=/usr/local/oracle"); /*Opent the connection*/ $handle = ora_logon('s3560_xx@seora','xxxxxxx') or die ("Connection error"); $cursor = ora_open($handle); ?> 2. To send a query from Sybase through PHP: ora_parse (link , query); Example: Suppose we want to create the following table and input the data: first_db course (char) student (int) 'SEG3560' 150 If we want to store information into oracle: <? ora_parse($cursor, "create table first_db (course char(10), student int)") ; ora_parse($cursor, "insert into first_db values('SEG3560', 150)"); ?> Page 9
  • 10. SEG3560 Introduction to E-Commerce (Fall 2005) Tutorial – Php 3. To view the information retrieved from Sybase through PHP: ora_fetch (query_information) Example: <? ora_parse($cursor, "select * from first_db"); ora_exec($cursor); ora_commit($handle); $numcols = 0; while(ora_fetch($cursor)){ $numcols = ora_numcols($cursor); for($column=0; $column < $numcols; $column++){ $data = trim(ora_getcolumn($cursor, $column)); if($data =="") $data = "NULL"; echo"$datat"; } } ?> Result: SEG3560 150 Page 10
  • 11. SEG3560 Introduction to E-Commerce (Fall 2005) Tutorial – Php Example: <html> <head> <title>PHP Introduction 123</title> </head> <? /*Set Environment */ putenv("ORACLE_SID=seora.se.cuhk.edu.hk"); putenv("ORACLE_HOME=/usr/local/oracle"); /*Opent the connection*/ $handle = ora_logon('s3560_30@seora','eFuoTyAp') or die ("Connection error"); $cursor = ora_open($handle); ora_parse($cursor, "create table first_db (course char(10), student int)") or die("Sql 1 error"); ora_parse($cursor, "insert into first_db values('SEG3560', 150)") or die("Sql 2 error"); /* Execute the sql*/ ora_exec($cursor); ora_commit($handle); /*Close the connection*/ ora_close($cursor); echo "Finished all the commands"; ?> </body> </html> Create the table “first_db” and put an instance into the table. http://www.se.cuhk.edu.hk/~s3560_30/write_db.php Read the content in the table. http://www.se.cuhk.edu.hk/~s3560_30/read_db.php Be careful, the first link will work with sql error, , Think why? Page 11
  • 12. SEG3560 Introduction to E-Commerce (Fall 2005) Tutorial – Php Tutorial 4 Supplementary Notes 1 – SQL Example Consider the following two tables, student_info and course_info: student_info Name (char 20) ID (int) Department (char 3) Supervisor (char 20) Agnes 00123456 SEM Prof. Cai Bonnie 00234567 PSY Prof. Chan Clara 00345678 ECO - Doris 01234567 SEM Prof. Madan course_info Course (char7) Instructor (char 20) Size (int) SEG3560 Prof. Madan 98 SEG3450 Prof. Madan 84 PSY3230 Prof. Chan 25 Database Manipulation: 1. Create a table: create table table_name (attribute1 data_type, attribute2 data_type, …) Example: create the table course_info: create table course_info (course char(7), instructor char(20), size int) 2. Remove a table: drop table table_name Example: remove the table course_info: drop table course_info Basic Database Access 1. Select Operation: select attibute1, attribute2, … from table1, table2, … where condition Example: Select all courses from the table course_info: select course from course_info Select all courses from the table course_info where the class size is greater then 50: select course from course_info where size>50 Select all courses taught by Professor Madan: select course from course_info where instructor=’Prof. Madan’ Select all courses offered by SEG: select course from course_info where course like ‘SEG%’ Page 12
  • 13. SEG3560 Introduction to E-Commerce (Fall 2005) Tutorial – Php Select all students whose supervisor has taught at least one course: select student_info.name from student_info, course_info where student_info.supervisor=course_info.supervisor. Select all records from the table student_info select * from student_info 2. Insert Operation insert into table_name values (value1, value2, …) OR insert into table_name values (attribute1=value1, attribute2=value2, …) Example: Insert the course SEG5010 taught by Professor Yu with class size 25 in the table: insert into course_info values (‘SEG5010’, ‘Prof. Yu’, 25) Insert the student Eddie (01345678) studying in ECO: insert into student_info values (name=‘Eddie’, id=01345678, department=‘ECO’) 3. Delete Operation delete from table_name where condition Example: Delete all records from the table course_info: delete from course_info Delete all students who are studying in ECO: delete from student_info where department=’ECO’ 4. Update Operation: update table_name set attribute1=value1, attrubute2=value2… where condition Example: Change the class size of all classes to 40: update course_info set size=40 Change the class size of the course PSY3230 to 40: update course_info set size=40 where course=’PSY3230’ Note: Different databases support different data types. However, some data types are supported by all databases, such as: integer (int), real number (real) and character (char (n)). Page 13
  • 14. SEG3560 Introduction to E-Commerce (Fall 2005) Tutorial – Php Tutorial 4 Supplementary Note 2 – Web Page and Sybase Creating web pages within SE department 1. Create a directory named /public_html under the root directory of your Unix account. 2. Upload or create all of the necessary files and directories to the directory /public_html 3. Change the access mode to all of the files and directories (as well as the /public_html) to 755 (owner—full control of all the file/directory; group and public—only could read or execute the file/directory). If you are under Unix environment, simply type: Chmod –R 755 /public_html* in your root directory 4. You could view your web pages using the following URL: www.se.cuhk.edu.hk/~XXX where XXX is your account name. Page 14