INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Delphi, PHP and MySQL

How do I develop the PHP code to handle the request from Delphi by towerbase
Posted: 27 Jul 04 (Edited 28 Jul 04)

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>

Back to Embarcadero: Delphi FAQ Index
Back to Embarcadero: Delphi Forum

My Archive

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close