Affichage des articles dont le libellé est Tutorial PHP. Afficher tous les articles

Using Flash, php and MySql / PDF


 Using Flash, php and MySql / PDF








Sample of the pdf document :









A typical Flash application, like a simple HTML web page, does not collect and store data on the server computer.  To store information, you need to use a file or a database and connect to the file or database using so-called server-side or middleware software.  Similarly, a typical php application accepts form data from a HTML form and produces an HTML document. This example demonstrates using Flash and php to store data in and extract data from a MySql database.  Both php and MySql are considered Open Source tools. 

The application keeps track of votes cast for 4 choices.  It is intended to represent a polling application, not a voting application.  Please note that a real voting application would need to incorporate features to allow only legitimate voters to vote and to only vote once.  A debate is going on now concerning various systems for electronic voting.  One feature considered critical by many, though not all, is that the system produce a paper trail for each vote.  This toy application does not include any of these features.  The intent is to demonstrate how Flash can connect to a php script.

Before continuing, one more warning:  A basic contract with an Internet Service Provider generally would not include support of php scripts or MySql (or any other) database.  This application and tutorial assumes php and MySql support and, moreover, assumes that a table has been created and initialized to hold the polling data. 

It is assumed that the reader has some background using Flash.  This document will explain the features of the application, not give step-by-step instructions on how to replicate it.

The initial screen for the Flash interface is the following:

If the person responds by clicking on the radio button next to Other and then Submit vote, the following screen results (at this point for this application.  I do not know where these 'votes' came from—perhaps my students).


The Flash interface consists of
  • the static text field with the words "If you had to vote today, would you vote for …."
  • 4 radio button components
  • 1 push button component
  • A dynamic text field, marked as accepting HTML tags and with a boundary

There are two layers: one layer, named board, holds all the graphics; the other layer, called actions, holds the ActionScript.  This is not necessary but is a standard way to organize an application.

The static text field is created in the usual way, using the text tool (icon A).

The radio buttons are created by clicking on the radio button icon on the component panel and dragging a button to the Stage.  The screen shot below shows the Property panel as set up for the Bush button.  In this case, the label and the data are similar.  That does not have to be the case.  Notice also the Group Name.  All four buttons would have the same group name. This works to make the Flash engine make sure that only one button is clicked.  Notice that there is no Change Handler.  This is because for this application, we wait for the 'voter' to click on the Submit Vote push button.  The Initial state and the Label Placement were left unchanged.   You need to do this for as many times as you want choices.  





Click here for  Download PDF / FREE

Using Flash, php and MySql / PDF





0

Learn basic PHP in 6 weeks / PDF


Learn basic PHP in 6 weeks / PDF







Table of Contents:





1. Getting started

2. Commenting your code

3. Language Reference
            3.1 Types
            3.2 Variables
            3.3 Constants
            3.4 Operators

4. for and while Loop

5. Handling Forms

6. Emails

7. Date and Time functions

8. PHP include function - creating the Header and Footer

9. How to set up a mysql database

10. How to set up tables in the interface

11. Cookies and Sessions

12. How to create table through PHP

13. Case study: a CMS (content management system) or Blog



-------------------------------------------------





Sample of the pdf document :






1.    INTRODUCTION:

PHP (recursive acronym for "PHP: Hypertext Preprocessor").

PHP started out as a small open source project that evolved as more and more people found out how useful it was. Rasmus Lerdorf unleashed the first version of PHP way back in 1994. Now it has version 4.0.3 with numerous improvements and refinements over the original release.

PHP is a server side scripting language that is embedded in HTML. It is used to manage dynamic content, databases, session tracking, even build entire e-commerce sites. It is integrated with a number of popular databases, including MySQL, PostgreSQL, Oracle, Sybase, Informix, and Microsoft SQL Server.

Common uses of PHP:

  • It performs system functions, i.e. from files on a system it can create, open, read, write, and close them.
  • It can handle forms, i.e. gather data from files, save data to a file, thru email you can send data, return data to the user.
  • You can add, delete, modify elements within your database thru PHP.
  • Access cookies variables and set cookies.
  • Using PHP, you can restrict users to access some pages of your website.
  • It can encrypt data.

Now, we will walk through a few simple examples so you can have an idea. Keep in mind that this is just a quick starter.

"Hello, World!"

To get a feel for PHP, first start with simple PHP scripts. Since "Hello, World!" is an essential example, first we will create a friendly little "Hello, World!" script.

As mentioned earlier, PHP is embedded in HTML. (You could have a file that contains almost no HTML, but usually it's a mixture.) That means that in amongst your normal HTML (or XHTML if you're cutting-edge) you'll have PHP statements like this:

<body bgcolor="white">
  <strong>How to say "Hello, World!"</strong>
           <?php echo "Hello, World!";?>
  <br>
It is simple.
</body>
It is simple. Just an "echo" statement, and that's it. But it does teach us something about the language. (By the way, if you examine the HTML output, you'll notice that the PHP code is not present in the file sent from the server to your Web browser. All of the PHP present in the Web page is processed and stripped from the page; the only thing returned to the client from the Web server is pure HTML output.)............








Click here for  Download PDF / FREE


Learn basic PHP in 6 weeks / PDF






0

PHP script with MySQL


 PHP script with MySQL








Sample of the pdf document :









<HTML>
<head>
<title>PHP: Sample Form 1... V22.0380</title>
</head>
<body bgcolor = lightblue>

Composers on File for  <?php echo $_POST['lname']; ?>.

<?php
 /* Connecting, selecting database */
$link = mysql_connect("", "dse7916", "") or die("Could not connect : " . mysql_error());
/* echo "Connected successfully"; -- for testing purposes */
mysql_select_db("dse7916") or die("Could not select database");

/* Performing SQL query */
$query = "SELECT * FROM composers";
$result = mysql_query($query) or die("Query failed : " . mysql_error());

/* Printing results in HTML */
echo "<table>\n";
 while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
    echo "\t<tr>\n";
    foreach ($line as $col_value) {
    echo "\t\t<td>$col_value</td>\n";
      }
      echo "\t</tr>\n";
      }
      echo "</table>\n";

  /* Free resultset */
  mysql_free_result($result);

 /* Closing connection */
mysql_close($link);
 ?>

</body>
</html>


Sample #2: Using PHP to find records in the MySQL Database using selection criteria (in this case, on the field “country”)

#!/usr/local/bin/php

<HTML>
<head>
<title>PHP: Sample Form 2... V22.0380</title>
</head>
<body bgcolor = lightblue>

Composers on File for  <?php echo $_POST['lname']; ?>.

<?php
 /* Connecting, selecting database */
$link = mysql_connect("", "dse7916", "") or die("Could not connect : " . mysql_error());
/* echo "Connected successfully"; -- for testing purposes */
mysql_select_db("dse7916") or die("Could not select database");

/* Performing SQL query */
$query = "SELECT * FROM composers WHERE origin='German'";
$result = mysql_query($query) or die("Query failed : " . mysql_error());

/* Printing results in HTML */
echo "<table>\n";
 while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
    echo "\t<tr>\n";
    foreach ($line as $col_value) {
    echo "\t\t<td>$col_value</td>\n";
      }
      echo "\t</tr>\n";
      }
      echo "</table>\n";

  /* Free resultset */
  mysql_free_result($result);

 /* Closing connection */
mysql_close($link);
 ?>

</body>
</html>


Sample #3: Using a variable to determine the selection criteria in a query

#!/usr/local/bin/php

<HTML>
<head>
<title>PHP: Sample Form 3... V22.0380</title>
</head>
<body bgcolor = lightblue>

Composers on File for  <?php echo $_POST['lname']; ?>.

<?php
 /* Connecting, selecting database */
$link = mysql_connect("", "dse7916", "") or die("Could not connect : " . mysql_error());
/* echo "Connected successfully"; -- for testing purposes */
mysql_select_db("dse7916") or die("Could not select database");

/* setting a variable for the nation of origin */
$country = "Russian";

/* Performing SQL query */
$query = "SELECT * FROM composers WHERE origin='$country' ";
$result = mysql_query($query) or die("Query failed : " . mysql_error());

/* Printing results in HTML */
echo "<table>\n";
 while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
    echo "\t<tr>\n";
    foreach ($line as $col_value) {
    echo "\t\t<td>$col_value</td>\n";
      }
      echo "\t</tr>\n";
      }
      echo "</table>\n";

  /* Free resultset */
  mysql_free_result($result);

 /* Closing connection */
mysql_close($link);
 ?>

</body>
</html>





Sample #4: Allowing the user to select the country and passing the variable as a parameter to the PHP script

#!/usr/local/bin/php

<HTML>
<head>
<title>PHP: Sample Form 3... V22.0380</title>
</head>
<body bgcolor = lightblue>

<h2>Composers on File </h2>
<p>
<?php............









Click here for  Download PDF / FREE





0

Quick PHP tutorial



 Quick PHP tutorial











Sample of the pdf document :











PHP script may be embedded within HTML documents

– meaning PHP and HTML code can both happily co-exist in the same file. All embedded PHP code must be contained within <?php and ?> tags so it can be readily recognized by the PHP engine for interpretation. Typically the PHP code will write content into the body section of the HTML document, which is then sent to the web browser.

1: Launch a plain text editor and create this valid barebones HTML5 document with an empty body section
<!DOCTYPE HTML>
<html lang=“en”>
<head><meta charset=”UTF-8”>
<title>Getting Started With PHP</title></head>
<body>
</body>
</html>


2: Insert tags into the body section to contain PHP code<?php?>

3: Now insert between the PHP tags a descriptive comment and a line of code to write content into the body section
# Write the traditional greeting.echo ‘<h1>Hello World!</h1>’ ;









 Click here for  Download PDF / FREE

 Quick PHP tutorial

0

Tags