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 commentaires: