Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 10 of 11 total
Thread Simple but Complete Website
Wed, Mar 21 2012 2:02 AMPermanent Link

M Reyneke

This is by no means an example of correct procedures.

Maybe there are other users that battle as much as I did, and could benefit from this example.

It contains phps for sending email, connect, read and post to a MySql database.

I would be happy if the boffins could fix anything that is incorrect, and the not so boffins could learn something.



Attachments: web.zip
Wed, Mar 21 2012 8:56 AMPermanent Link

Walter Matte

Tactical Business Corporation

Hendrik:

Thanks!  Very informative!

Walter
Tue, May 1 2012 12:30 PMPermanent Link

Malcolm Taylor

Thanks Hendrik

I did not want to distract Tim at this time so I tried everything I
could think of to post a simple name=value request to a PHP script.  I
got nowhere.  Frown

Then I looked at your example.  I did not expect to have to construct
each request in the way you demonstrated .. but it works.  Smile

Malcolm
Thu, May 3 2012 8:57 AMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Malcolm,

<< I did not want to distract Tim at this time so I tried everything I could
think of to post a simple name=value request to a PHP script.  I got
nowhere.  Frown>>

The problem is often that the PHP script on the other end wants things in a
specific form POST format, which is often the multi-part, form-data MIME
format.

You can post plain text (key-value pairs, etc.) also - you just need to
handle everything yourself on the PHP side.

If you want to post the email-thankyou.php script, I can tell you what you
need to change to get it to work with key-value pairs.

Tim Young
Elevate Software
www.elevatesoft.com
Thu, May 3 2012 12:56 PMPermanent Link

Malcolm Taylor

Tim Young [Elevate Software] wrote:

>
> You can post plain text (key-value pairs, etc.) also - you just need
> to handle everything yourself on the PHP side.
>

Hi Tim,  I do not want to distract you!  Smile

But my little EWB app is now working nicely using Hendrik's method of
posting the key-value pairs.

I am using a phpmailer instead of mailto, but in my php script I simply
have:
[code]
 ...
 // get SqlStr
 $TheSQL = $_POST['SqlStr'];
 // pop it into an email and send to <me>
 ....
[code]

To pass in the key-value using html I would have had a <form> and
included something like:
<input type="text" name="SqlStr" value=$SqlStr>

But from Hendrik's example I am now constructing the Request in EWB as
follows:
[code]
  with MyServerRequest do
  begin
     ResponseContent.LineSeparator:=#13+#10;
     OnComplete:=RequestComplete;
     URL := <somescript.php>;
     RequestHeaders.Values['Content-Type'] := 'multipart/form-data;
boundary=AaB03x';
     with RequestContent do
     begin
     Add('--AaB03x');
     Add('Content-Disposition: form-data; name="SqlStr"');
     Add('');
     Add(SqlStr);
     Add('--AaB03x');
     end;
     Method := rmPost;
     RequestQueue.AddRequest(MyserverRequest);
  end;    
[code]

It just seems to be a long winded way of doing it.  
If this is the official way to do it I could obviously refactor it a
little to have a function construct the request from parameters such as
(name, value, phpscript) to make it more readable.

Maybe the Help (to come) will reveal a much easier way to do it.  Smile

Malcolm
Thu, May 3 2012 5:30 PMPermanent Link

Raul

Team Elevate Team Elevate

I think part of this is due to the fact that you're using the POST
method. So alternatives i can think of are:

1. use GET and append your sqlstr to the URL itself. this would not work
for anything too long but for simple stuff should be quite fine.
So instead of url being "somescript.php" you would use
"somescript.php?SqlStr=<put your string here>" and then use the
"$_GET['SqlStr']" in PHP instead.

2. The other option would be to use JSON or XML and encode your data in
there and POST to server and just parse the whole thing from posted data
rather than key/value pair. For simple things it's more work but it
scales nicely when you either need to add more fields or send multiple
records (like database records) since you only need to change the
parsing logic and not add parameters

Raul


On 5/3/2012 12:56 PM, Malcolm wrote:
> It just seems to be a long winded way of doing it.
> If this is the official way to do it I could obviously refactor it a
> little to have a function construct the request from parameters such as
> (name, value, phpscript) to make it more readable.
>
> Maybe the Help (to come) will reveal a much easier way to do it.  Smile
Thu, May 3 2012 6:38 PMPermanent Link

Malcolm Taylor

Raul wrote:

> I think part of this is due to the fact that you're using the POST
> method. So alternatives i can think of are:
>

Hi Raul

The curent little app is just a test though it does have a use as it
stands.

The real app I have in mind would transfer a lot more data so I don't
think that rmGet will be an option.
I have the prospective app already running in pure PHP on the server
side but I am hoping that EWB will do a better or more convenient job
of the GUI.
Still it looks as though I may have to continue using PHP for its
powerful string functions unless I can convert the whole thing to a
database app.

My challenge is that all the data is transient so it would mean
creating and dropping temporary tables all the time.  But if these are
created on the client side I can see it being practical.

I need to find out just what EWB will be able to do for me.  I am
hopeful so far.  Smile

Malcolm
Mon, May 7 2012 12:54 PMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Malcolm,

<< But my little EWB app is now working nicely using Hendrik's method of
posting the key-value pairs. >>

The issue is that PHP, by default, always wants POST data in form-encoded
format.  Which is fine, but often overkill when you only want to send over
some simple data, or if you want to send something that isn't form-encoded
data, such as JSON.

In such a case, you can use the stdin (php://input) method of reading the
POSTed data directly:

http://php.net/manual/en/wrappers.php.php

And then something like this to parse the key-value pairs:

http://www.bytemycode.com/snippets/snippet/69/

However, it's pretty clear that I should probably just add some higher-level
functionality to the TServerRequest component (or something similar) to deal
with form data directly and allow people to use the standard $_POST
variables in PHP.  It will still allow for JSON, etc. by just allowing
someone to pop the whole thing into a form variable called "data" or
something similar.

Tim Young
Elevate Software
www.elevatesoft.com
Mon, May 7 2012 4:15 PMPermanent Link

Malcolm Taylor

Tim Young [Elevate Software] wrote:
>
> However, it's pretty clear that I should probably just add some
> higher-level functionality..

Sounds like a plan to me.  Smile
Thanks for the other pointers.  
I have been steering clear of JSON and XML, but I guess that can't go
on much longer.

Malcolm
Thu, May 10 2012 5:06 AMPermanent Link
 Cancelled Message Cancelled
Page 1 of 2Next Page »
Jump to Page:  1 2
Image