Presentation is loading. Please wait.

Presentation is loading. Please wait.

Application Development Description and exemplification of server-side scripting language for server connection, database selection, execution of SQL queries.

Similar presentations


Presentation on theme: "Application Development Description and exemplification of server-side scripting language for server connection, database selection, execution of SQL queries."— Presentation transcript:

1 Application Development Description and exemplification of server-side scripting language for server connection, database selection, execution of SQL queries and extraction of results. Description and exemplification of forms processing to insert and amend data. Description of structure of HTML forms including: – the element and its action and method attributes – the element and its type, name and value attributes

2 Application Development - Description and exemplification of server-side scripting language for server connection Server-side scripting is a web server technology in which a user's request is fulfilled by running a script directly on the web server to generate dynamic HTML pages. It is usually used to provide interactive web sites that interface to databases or other data stores. This is different from client-side scripting where scripts are run by the viewing web browser. The primary advantage to server-side scripting is the ability to highly customize the response based on the user's requirements, access rights, or queries into data stores.

3 Application Development - Description and exemplification of server-side scripting language for server connection You have to connect to the database server and select the database to be used before you can execute MySQL statements. PHP has a number of commands which are used for this purpose. The following PHP function call establishes the connection: – mysql_connect(address, username, password); The mysql_connect function shown above, for example, returns a number that identifies the connection that has been established. We need to store this value so that we can make use of it later to select the database we wish to use. – $varconnect = mysql_connect("localhost", "root", "password"); What's important to see here is that the value returned by mysql_connect (which we'll call a connection identifier) is stored in a variable named $varconnect.

4 Application Development- Description and exemplification of server-side scripting language for database selection Selecting that database in PHP uses another function call: – mysql_select_db(database_name, database_connection); For example: – mysql_select_db("freedomofmidnight", $varDBconnect); The $varDBconnect variable that contains the database connection identifier is used to tell the function which database connection to use. This parameter is actually optional. When it's omitted, the function will automatically use the details of the last connection opened. This function returns true when it's successful and false if an error occurs.

5 Application Development- Description and exemplification of server- side scripting language execution of SQL queries and extraction of results All SQL queries are executed using the mysql_query() function. This executes the query and returns the results set as an array of values. – $result_array=mysql_query($query_string); This can be used with the @ symbol, as before, to suppress error messages as @mysql_query($query_string). This allows you to use the mysql_error function to access the last error set by the MySQL server. MySQL also keeps track of the number of rows affected by INSERT, DELETE and UPDATE queries and the number of rows in the results of a SELECT query. This number can be accessed using the mysql_affected_rows() function.

6 Application Development- Description and exemplification of server- side scripting language execution of SQL queries and extraction of results For most SQL queries, the mysql_query() function returns either true (success) or false (failure) but for SELECT queries the function returns the result set, the answer table, generated by the query. False is still returned if the query fails for any reason. – $result = @mysql_query("SELECT name FROM publisher"); if (!$result) { echo(" Error performing query: ". mysql_error(). " "); exit(); } As long as no error is encountered in processing the query, the above code places a result set that contains the names of all the publishers stored in the publisher table into the variable $result. There is no practical limit on the number of publishers in the database so the result set generated can be very large.

7 Application Development- Description and exemplification of forms processing to insert and amend data. For many applications of PHP, the ability to interact with users who view the Web page is essential. Server-side scripting languages such as PHP have a more limited scope when it comes to user interaction. As PHP code is activated when a page is requested from the server, user interaction can occur only in a back-and-forth fashion: the user sends requests to the server, and the server replies with dynamically generated pages. The key to creating interactivity with PHP is to understand the techniques used to send information about a user's interaction along with his or her request for a new Web page.

8 Application Development- Description and exemplification of forms processing to insert and amend data. The GET Method: – The simplest method that can be used to send information along with a page request uses the URL query string. If you've ever seen a URL with a question mark following the file name, you've seen this technique in use. Hi, I'm Charlie! – The above code is a link created in an HTML document, – This is a link to a file called welcome1.php, but as well as linking to the file, we're also passing a variable along with the page request. The variable is passed as part of the query string, which is the portion of the URL that follows the question mark. The variable is called name and its value is Charlie. To restate, we have created a link that loads welcome1.php, and informs the PHP code contained in the file that name equals Charlie.

9 Application Development- Description and exemplification of forms processing to insert and amend data. The GET Method: – To really understand the results of this process, we need to look at welcome1.php – Now, if you use the link in the first file to load this second file, you'll see that the page says "Welcome to our Website, Charlie!" – PHP automatically creates an array variable called $_GET that contains any values passed in the query string. $_GET is an associative array, so the value of the name variable passed in the query string can be accessed as $_GET['name']. Our script assigns this value to an ordinary PHP variable ($name) and then displays it as part of a text string using the echo function.

10 Application Development- Description and exemplification of forms processing to insert and amend data. The POST Method: – It's not always desirable - or even technically feasible - to have the values appear in the query string. What if we included a tag in the form, to let the user enter a large amount of text? A URL that contained several paragraphs of text in the query string would be ridiculously long, and would exceed by far the maximum length of the URL accepted by browsers. – The alternative is for the browser to pass the information invisibly, behind the scenes. The code for this looks exactly the same, but we use the POST method instead of the GET method used in the last example.

11 Application Development- Description and exemplification of forms processing to insert and amend data. The POST Method: This HTML code would be entered in the link Untitled Document First Name: Last Name:

12 Application Development- Description and exemplification of forms processing to insert and amend data. The POST Method: As we're no longer sending the variables as part of the query string, they no longer appear in PHP's $_GET array. Instead, they are placed in another array reserved especially for 'posted' form variables: $_POST. The php would be as follows: Untitled Document <?php $firstname = $_POST['firstname']; $lastname = $_POST['lastname']; echo( "Welcome to my Website, $firstname $lastname!" ); ?>

13 Application Development- Description and exemplification of forms processing to insert and amend data. The IF control structure allows decisions to be made: The php would be as follows: Untitled Document <?php $firstname = $_GET['firstname']; $lastname = $_GET['lastname']; if ( $firstname == 'Charlie' and $lastname == 'Burton' ) { echo( 'Hi, How can I help you, Charlie' ); } else { echo( "Welcome to my Website, $firstname $lastname!" ); } ?>

14 Application Development- Description and exemplification of forms processing to insert and amend data. The while loop uses a condition to determine how many times a piece of code is executed (conditional loop): The php would be as follows: Untitled Document <?php $count = 1; while ($count <= 10) { echo( "$count " ); $count++; } ?>

15 Application Development- Description and exemplification of forms processing to insert and amend data. The For loop is used when a set number of repetitions are required. Often this is when a value is being counted. (Fixed Loop) The php would be as follows: Untitled Document <?php for ($count = 1; $count <= 10; $count++) { echo( "$count " ); ?>

16 Application Development - Description of structure of HTML forms HTML documents are text files made up of HTML elements. HTML elements are defined using HTML tags. HTML Tags – HTML tags are used to mark-up HTML elements – HTML tags are surrounded by the two characters – The surrounding characters are called angle brackets – HTML tags normally come in pairs like and – The first tag in a pair is the start tag, the second tag is the end tag – The text between the start and end tags is the element content – HTML tags are not case sensitive, means the same as

17 Application Development - Description of structure of HTML forms Basic HTML Tags Defines an HTML document Defines the document's body to Defines header 1 to header 6 Defines a paragraph Inserts a single line break Defines a horizontal rule Defines a comment

18 Application Development - Description of structure of HTML forms Tables are defined with the tag. A table is divided into rows (with the tag), and each row is divided into data cells (with the tag). The letters td stands for "table data," which is the content of a data cell. A data cell can contain text, images, lists, paragraphs, forms, horizontal rules, tables, etc. row 1, cell 1 row 1, cell 2 row 2, cell 1 row 2, cell 2

19 Application Development - Description of structure of HTML forms Basic Table HTML Tags Defines a table Defines a table header Defines a table row Defines a table cell Defines a table caption Defines groups of table columns Defines the attribute values for one or more columns in a table Defines a table head Defines a table body Defines a table footer

20 Application Development - Description of structure of HTML forms HTML tag The option element defines an option in the drop-down list. Example Volvo Saab Opel Audi

21 Application Development - Description of structure of HTML forms HTML Elements Here is an example: Title of page This is my first homepage. This text is bold This is an HTML element: – This text is bold The HTML element starts with a start tag: The content of the HTML element is: This text is bold The HTML element ends with an end tag: The purpose of the tag is to define an HTML element that should be displayed as bold.

22 Application Development - Description of structure of HTML forms Forms – A form is an area that can contain form elements. – Form elements are elements that allow the user to enter information (like text fields, textarea fields, drop-down menus, radio buttons, checkboxes, etc.) in a form. A form is defined with the tag. eg –

23 Application Development - Description of structure of HTML forms Input – The most used form tag is the tag. The type of input is specified with the type attribute. The most commonly used input types are explained below. – Text Fields Text fields are used when you want the user to type letters, numbers, etc. in a form. First name: Last name:

24 Application Development - Description of structure of HTML forms Input – The most used form tag is the tag. The type of input is specified with the type attribute. The most commonly used input types are explained below. – Password Fields Password fields are used when you want the users entry to be hidden with *. User ID: Password:

25 Application Development - Description of structure of HTML forms Radio Buttons Radio Buttons are used when you want the user to select one of a limited number of choices. Male Female Note that only one option can be chosen.

26 Application Development - Description of structure of HTML forms Checkboxes – Checkboxes are used when you want the user to select one or more options of a limited number of choices. I have a bike: I have a car: I have an airplane:

27 Application Development - Description of structure of HTML forms The Form's Action Attribute and the Submit Button – When the user clicks on the "Submit" button, the content of the form is sent to another file. The form's action attribute defines the name of the file to send the content to. The file defined in the action attribute usually does something with the received input. Username: – Username: If you type some characters in the text field above, and click the "Submit" button, you will send your input to a page called "html_form_action.asp". That page will show you the received input.


Download ppt "Application Development Description and exemplification of server-side scripting language for server connection, database selection, execution of SQL queries."

Similar presentations


Ads by Google