Скачать презентацию LIS 651 lecture 0 Gathering and showing data Скачать презентацию LIS 651 lecture 0 Gathering and showing data

a9f7bcb8050e2ac73cb60367ef2ceab7.ppt

  • Количество слайдов: 58

LIS 651 lecture 0 Gathering and showing data Thomas Krichel 2006 -03 -11 LIS 651 lecture 0 Gathering and showing data Thomas Krichel 2006 -03 -11

course resources • Course home page is at http: //wotan. liu. edu/home/krichel/courses/lis 651 n course resources • Course home page is at http: //wotan. liu. edu/home/krichel/courses/lis 651 n 06 s • The course resource page http: //wotan. liu. edu/home/krichel/courses/lis 651 • The class mailing list https: //lists. liu. edu/mailman/listinfo/cwp-lis 651 -krichel • Me. – Send me email. Unless you request privacy, I answer to the class mailing list. – Skype me at thomaskrichel. Get skype from skype. com.

today • We introduce PHP. Understanding PHP is the most difficult aspect of the today • We introduce PHP. Understanding PHP is the most difficult aspect of the course. • We look at forms filling in to prepare for active web sites. • We look at how PHP can be used to show the data that we get from the form. • You should think about what data to get and how to show it. • Thomas has built a little shop with form and PHP.

PHP introduction • PHP is the PHP hypertext processor. • It is a tool PHP introduction • PHP is the PHP hypertext processor. • It is a tool that allows for server-side scripting. • It is an interpreted language. – – You write a series of statements. Apache hands these statements to the PHP interpreter. The interpreter executes these statements one by one. When it find an error, it stops running and signals the error. • Compiled languages are different. They read the whole program before starting to execute it.

Apache and PHP • When a file ends in. php, is not simply sent Apache and PHP • When a file ends in. php, is not simply sent down the http connection like other files. • Instead, apache reads the file. If it finds PHP parts in the file, it sends them to the PHP processor. • This processor is a model that lives inside Apache.

good old wotan • Remember we duplicate validated. html when creating a new file. good old wotan • Remember we duplicate validated. html when creating a new file. • Right-click on validated. html, choose duplicate. • You may be asked to supply your password again. • You erase the contents of the dialog box that suggests a new file name and put your new file name in there. • If it contains PHP code, it has to end in. php.

first PHP script • Create a file with the name info. php, and the first PHP script • Create a file with the name info. php, and the following contents • nothing else. This will create a test page that tells you everything PHP knows about. Look at some of the variables.

comment on info. php • If a file has the ending. php, Apache may comment on info. php • If a file has the ending. php, Apache may not show the entire file to the client as is. • Instead Apache reads the file. When it finds “”. • We can call any part of the file between “” a PHP part of the file. • Parts of the file that are not in a PHP part are sent to the clients as such.

output of phpinfo() • phpinfo() create a whole web page for you, that validates output of phpinfo() • phpinfo() create a whole web page for you, that validates against a loose HTML specification. • That page contains a lot of technical detail. • The section we may be interested in is “PHP Variables”. It contains variables that we may be interested in. These are variables that PHP can understand – from its environment – from the client

the magic of PHP • The client never sees the PHP code. It only the magic of PHP • The client never sees the PHP code. It only sees what the PHP processor has done with the code. • You can write normal HTML code, and you can switch to writing PHP code pretty much at any stage. • You can have several PHP parts. • PHP parts can not be nested. • The contents of the PHP part can be called a PHP script.

statements • Like a normal text is split into sentences, a PHP script is statements • Like a normal text is split into sentences, a PHP script is split into statements. • A PHP script contains one or more statements. • Each statements tells the interpreter something. • Each statement is ended by a semicolon. • In our first script there is only one statement. • Each statement is ended with a semicolon! • Think of a statement like a rule in CSS. But never forget the semicolon!

expressions • The stuff before the semicolon is called an expression. • You can expressions • The stuff before the semicolon is called an expression. • You can think of an expression as anything anyone may want to write in a computer program. • So an expression is just a way to talk about “stuff” in a program in a more edifying way than just calling it “stuff”.

functions • phpinfo() is a function. • Functions are one of the most fundamental functions • phpinfo() is a function. • Functions are one of the most fundamental concepts in computer programming. • A function is an expression that does something to something else. The “something else” is in the parenthesis. It is called the argument of the function. • phpinfo() is a function. Its argument is empty.

second php script: hello. php • Normally we write HTML code and then we second php script: hello. php • Normally we write HTML code and then we add PHP parts. • Take validated. html, copy to hello. php • make the body

• Validate the resulting XHTML.

comment on hello. php • print() is also a function. prints its argument. Here comment on hello. php • print() is also a function. prints its argument. Here the argument is a string. A string is a sequence of characters enclosed by single or double quotes. • For print, the () can be omitted. • You could have written three statements "; print "Hello, world!"; print "

"; ? >

good style • Write each statement on a new line. • Add plenty of good style • Write each statement on a new line. • Add plenty of comments. There are three styles of comments in a PHP program – // the rest of the line is a comment – # the rest of a line is a comment – /* this is a comment */ • Only last style can be used over several lines. • Do you recognize two of the commenting styles?

$greeting

"; ? >" src="https://present5.com/presentation/a9f7bcb8050e2ac73cb60367ef2ceab7/image-17.jpg" alt="another way to write hello. php $greeting
"; ? >" /> another way to write hello. php $greeting"; ? > • Here $greeting is a variable. The first statement assigns it the string value "Hello, world!". The second statement prints it out. • This example is important because it illustrates the concept of a variable. • The name of the variable is greeting.

Forms • Forms are parts of an HTML document that users can fill in. Forms • Forms are parts of an HTML document that users can fill in. They may include buttons, checkboxes, text areas, file selections. • The thing that users fill in are called the controls of the form. • Some controls are hidden. • Controls are submitted to PHP in the form of variables. Each control in the HTML form becomes a variable in PHP. This is seen later.

forms examples • Here is an example in http: //wotan. liu. edu/home/krichel/coures/lis 651/ex amples/forms forms examples • Here is an example in http: //wotan. liu. edu/home/krichel/coures/lis 651/ex amples/forms • Elements used in forms use a special attribute group that I will call the “form attributes”. I will discuss them now.

form attribute: tabindex= • Stupid users use the mouse to fill in form. Smart form attribute: tabindex= • Stupid users use the mouse to fill in form. Smart users use the tab character on the keyboard. It is much quicker. • if you set the tabindex= on a in input, you can set the order. The value of the attribute is a number between 0 and 32767. The input with a lower number will be dealt with before the one with a higher number.

form attribute: readonly= • If you set readonly= form attribute: readonly= • If you set readonly="readonly" the control can only be read but not set. This means – It can receive focus but cannot be modified by the user. – It is included in tabbing navigation. – It is transmitted to the server for processing. • readonly= is not set by default.

form attribute: disabled= • If you set disabled= form attribute: disabled= • If you set disabled="disabled" the control can only be read but not set. This means – it can not receive focus and can not be modified – it is excluded in tabbing – it is not transmitted to the server for processing. • disabled= in not set by default.

<form> • This element encloses a form. • All form elements (discussed now) should • This element encloses a form. • All form elements (discussed now) should be children of the element. • There can be more than one form in the HTML page, but it does not make much sense to have several s. • accepts the core and i 18 n attributes. And it has some other attributes. Some of these are required.

the action= attribute of <form> • It has a required action= attribute. – The the action= attribute of • It has a required action= attribute. – The value of this attribute is the location of a file that contains the action to execute when the form is submitted. – In our case, this will be the file name of the PHP script that deals with the form on wotan. • By default, scripts are executed using return on the browser while a form element has focus, or a special submit button.

method= of <form> • <form> admits a method= attribute. This attribute determines the http method= of • admits a method= attribute. This attribute determines the http method by which the form is submitted to the script. There are only two realistic choices – method="get" – method="post" • When the form is submitted the http request line that follows will have the method GET or POST. • Validation requires lowercase values.

method= method="get" • If you use GET, the form data is transmitted by appending it to the URL of the script. Google's Web search does it that way, for example. • There is a standard way to write the data in the URL knows as Common Gateway Interface, CGI. It is of no further interest to us. • Advantage: you can bookmark the form. • Problem: there is a limit of 1024 chars for the URL, therefore only a limited information can be transmitted in this way.

method= method="post" • If you use post, the user agent sends the form as a POST message to the server. • The data is sent in the body of the http request. • Thus it can be as long as you want. • If you use POST you can set the MIME type of the data with a special attribute enctype=

more attributes to <form> • Here are two more attributes I will list for more attributes to • Here are two more attributes I will list for completeness – accept-charset= says what character sets will be accepted by the form – accept= says what MIME-types can be accepted

the form control <input/> • This element creates a control. Usually a form has the form control • This element creates a control. Usually a form has several s as well as text that explains the from. • Note the emptiness of the element. • It admits the core, i 18 n and the form attributes. • It requires a type= attribute and a name= attribute.

the type= attribute of <input/> • This attribute can only take the following values the type= attribute of • This attribute can only take the following values – – – – – ‘text’ enter text ‘password’ enter text, but don't echo on screen ‘checkbox’ enter checks on boxes ‘radio’ check one select ‘submit’ press to submit form ‘reset’ reset form ‘file’ upload file (can only be done with POST) ‘hidden’ hidden form data, not shown ‘image’ image map submission, not covered further ‘button’ a button

the name= attribute of <input/> • This give a name to the control that the name= attribute of • This give a name to the control that the users are setting. • The script that is found by the action= attribute will identify the controls by name. Therefore every control should have a different name.

control name and PHP variable • When the form is passed to the PHP control name and PHP variable • When the form is passed to the PHP script named with the action= attribute of the form, the controls are accessible as PHP variables. • If name is the name of the control, and if the method is POST, the control is read as the variable $_POST['name']. • If name is the name of the control, and if the method is GET, the control is read as the variable $_GET['name'].

the size= attribute of <input/> • It lets you set the size of the the size= attribute of • It lets you set the size of the input field. • Note that the size of the field may not limit the input to that size. • When the type is ‘text’ or ‘password’ the value you give to this field is the number of characters. • Otherwise it is the number of pixels.

the maxlength= attribute of <input/> • This sets the maximum length on the value. the maxlength= attribute of • This sets the maximum length on the value. • Note that this is different from the size of the input field because there is scrolling. • If you don't specify a maximum length there is no limit. • But it is good security to have a limit.

the value= attribute of <input/> • This gives the initial value of the <input/>. the value= attribute of • This gives the initial value of the . • The initial value is shown to the user. • value= is optional but should be given for the radio and checkbox type.

the checked= attributes of <input/> • When the input is of type 'radio', setting the checked= attributes of • When the input is of type 'radio', setting the checked= attribute to any value will tell the browser what button is initially set. Of course there can only be one of them. • When the input is of type 'checkbox', setting the checked= attribute to any value will make sure it is checked initially.

the src= attribute of <input/> • When the input is of type 'image' the the src= attribute of • When the input is of type 'image' the src= attribute gives the URL of the image. • This is for input using image maps.

your last name:" src="https://present5.com/presentation/a9f7bcb8050e2ac73cb60367ef2ceab7/image-38.jpg" alt="example • HTML file greet. html has

your last name:" /> example • HTML file greet. html has

your last name:

• PHP file greet. php has in addition to the usual HTML stuff.

the push button <button> • This makes a button for decoration. • It takes the push button

creating menus • This is done with <select> element. • Each <select> element can creating menus • This is done with element can have a number of

selectable choice: <option> • Within a <select> there a series of <option> elements that selectable choice:

value= attribute to <option> • value= can be used to set the value of value= attribute to

label= attribute to <option> • label= can be set to label the option. if label= attribute to

<optgroup> • This element has <option> elements as its children. • It takes the • This element has

the <textarea/> element • This creates a text area where you can put a the