TidHTTP component sample code to pass variables between a Delphi app and PHP form on the Web

EddieShipman put me on the right track with a problem I had last week by directing me towards using PHP as part of the solution. Now I have hit a snag with the TIdHTTP component usage, which I know very little about. I need some example code (Delphi) to pass a value between a Delphi app and a PHP form, but this value is unknown to the user, so it must find the value of the Delphi variable first and then pass it HIDDEN FROM SCRUTINY. Let's say the value to be passed is a string, and the variable name is 'Prod_Num' in the Delphi code. I click a button 'btnRegister' to submit the value to the PHP script, called 'form.php', located in "http://localhost/". Let's assume futher that the value will be received into the variable "$user_code" on the PHP side. Using these variable and component names (and TIdHTTP), could someone
give me some example code for the OnClick event of btnRegister? Please use the exact names as described because I am somewhat confused at the moment due to insomnia having extensively studied PHP and other new stuff (new to me, at least) for the last few days.

Hmmm....I see nobody has ventured an attempt to reply to this question in almost a day. I am going to up the points to 250 - I doubt the question is a difficult one for the experts, but I could be wrong. Come on, folks, help me out.
Regards
JDJVR

Thanks, ceoworks for the attempt, but it does not answer my question. I need to get a grip on the actual syntax of the idHTTP usage here. Although I can follow the logic you propose, your example differs fundamentally from what I ask in my question. Your example shows how values YOU INSERTED YOURSELF into the stringlist, is passed to the PHP form. If you read my original question carefully, however, you will notice that the VALUE of the variable that is passed to the PHP form is NOT KNOWN TO THE PROGRAMMER because it is generated by the Delphi app at runtime. I am not sure whether a simple reference to the Delphi variable name in the idHTTP component will work (I think not). Whoever tackles this question - could you try to use the EXACT example I proposed in my original question? I kept it short so as not to waste anybody's time, and it would eliminate any ambiguity. (All I really need to see is the syntax of how a simple Delphi variable (string, integer, whatever) is passed to a PHP script without knowing its value at designtime.)

I know pretty much nothing about PHP, but I will attempt to decode ceoworks "work" (with slight modifications):

//This should be easy, this is the event for the button, when its clicked
procedure TForm1.btnLoginClick(Sender: TObject);
var // variable declaration
SL: TStringList; // StringList variable, a more complex version of
begin
SL := TSTringList.Create; //Create the string list which will contain a <variable_Name>=<variable_Value> passed to a website
try
// I've never added values to a stringList like this, but I'll assume it works
SL.Values['user_code'] := Prod_Num; // OK create a Variable named user_code we will pass to PHP with the value of the DELPHI variable prod_num
SL.Text := Http.Post(http://localhost/logintest.php, SL); // This now sends a http request (type Post) with user_code=<value of Prod_Num>

if (SL.Text = 'OK') then //If the website return 'OK' meaning (i'm going to assume) that it was successful
begin
Caption := 'User authorized..'; // post was successful
end
else begin
Caption := 'User could not authorized'; // post was unsuccessful
end;
finally //This makes sure that if there are any errors in the above code, that we clean up after ourselves
SL.Free; // you *have* to free created objects that are not of type TComponent as they have no parent/ower the will clean them up
end;
end;

Woe is me! The answer was staring me in the face and I didn't see it. (Shows you what lack of sleep can do to a person). Thanks ErikPhilips and also ceoworks for your contributions - I managed to slap together some code which worked after reviewing your answers.

Regards
JDJVR

0

Featured Post

A positive customer journey is important in attracting and retaining business. To improve this experience, you can use Google Maps APIs to increase checkout conversions, boost user engagement, and optimize order fulfillment. Learn how in this webinar presented by Dito.

Objective:
- This article will help user in how to convert their numeric value become words.
How to use
1. You can copy this code in your Unit as function
2. than you can perform your function by type this code
The Code
(CODE)
The Im…

Introduction
Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview. I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…

Kernel Data Recovery is a renowned Data Recovery solution provider which offers wide range of softwares for both enterprise and home users with its cost-effective solutions. Let's have a quick overview of the journey and data recovery tools range he…

How can you see what you are working on when you want to see it while you to save a copy?
Add a "Save As" icon to the Quick Access Toolbar, or QAT.
That way, when you save a copy of a query, form, report, or other object you are modifying, you…