Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I develop the PHP code to handle the request from Delphi

Delphi, PHP and MySQL

How do I develop the PHP code to handle the request from Delphi

by  towerbase  Posted    (Edited  )
I'm assuming you know PHP. If you don't then you will need to get hold of a suitable tutorial. There's a good one on www.php.net

PHP can look a bit cryptic especially if you've not been exposed to a 'C' type language before. It also looks a lot like HTML - which essentially it is.

This is really simple standard PHP code. It checks that the parameters are valid, connects to the server, connects to the database and then issues a query to get the required rows from the table. For each row on the table it generates a paragraph tag, name and a closing paragraph tag.

Obviously the user name and password need to be changed to work for your particular MySQL database.
Code:
<html>
<head>
<title>Todays Birthdays</title>
</head>
<body>
<h1>The following have a birthday today</h1>
<?php
if (!isset($_GET['day'])) {
  die("<h2>day not specified</h2>");
}

if (!isset($_GET['month'])) {
  die("<h2>month not specified</h2>");
}

$day = $_GET['day'];
$month = $_GET['month'];

$cnx = mysql_connect('localhost','root','password');
if (!$cnx) {
  die('<h2>Unable to connect to database server</h2>');
}

if (!@mysql_select_db('birthsdb') ) {
  die('<h2>Unable to connect to birthsdb database</h2>');
}
$select = "SELECT name FROM birthdays WHERE MONTH(born)=$month AND DAYOFMONTH(born)=$day";
$result = @mysql_query($select);
if (!$result) {
  die("<h2>Unable to process: $select</h2>");
}

while ( $row = mysql_fetch_array ($result) ) {
  echo("\n<p>\n" . $row['name'] . "\n</p>");
}
?> 
}
To make life simple for the Delphi program that is going to read the HTML I've coded the <p>, birthday name and the </p> on different lines. The output will look something like:
<p>
Beatrix Potter
</p>
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top