Delphi代码

************************************************************************************************************************************

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient,
  IdHTTP, StdCtrls, ShellAPI;

type
  TForm1 = class(TForm)
    Button1: TButton;
    IdHTTP1: TIdHTTP;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
  strlist_ParamPost : TStringList ;
  class_IdHttp : TIdHTTP ;
begin
  strlist_ParamPost := TStringList.Create() ;
  class_IdHttp := TIdHTTP.Create(nil);
  try
    // 向目标PHP网址POST参数
    // strlist_ParamPost.Add('1=测试1') ;
    
       strlist_ParamPost.Add('1=aaaaa');

// TidHTTP属性设置
    class_IdHttp.ReadTimeout := 30*1000 ; // 超时设置
    class_IdHttp.Post('http://localhost/DelphiRequest/index.php', strlist_ParamPost) ;
    //打开网页,ShellExecute需要引入uses ShellAPI
    // ShellExecute(Application.Handle, nil, 'http://localhost/DelphiRequest/index.php', nil, nil, SW_SHOWNORMAL);
  finally
    FreeAndNil(class_IdHttp);
    strlist_ParamPost.Free() ;
end;
end;

end.
****************************************************************************************************************************************************************************************

php文件代码

新建一个文件夹DelphiRequest,然后在这个文件夹里建一个index.php写入代码

然后在输入本地地址http://localhost/DelphiRequest/index.php/就可以看到该PHP网页

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
</head>
<body>
<?php
if(count($_POST)!= 0)
{
$var_PostAllParma = "" ;
foreach($_POST as $var_Key => $var_Value)
{
$var_PostAllParma .= $var_Value."\r\n" ;
} $host = 'localhost';
$database = 'test';
$username = 'root';
$password = '****';
$selectName = '1';//要查找的用户名,一般是用户输入的信息
$pdo = new PDO("mysql:host=$host;dbname=$database", $username, $password);//创建一个pdo对象
$pdo->exec("set names 'utf8'");
$sql ="UPDATE delphi_test_content SET content= '$var_PostAllParma' WHERE ID='2'";
$stmt = $pdo->prepare($sql);
$rs = $stmt->execute(array($selectName));
// if ($rs) {
// // PDO::FETCH_ASSOC 关联数组形式
// // PDO::FETCH_NUM 数字索引数组形式
// while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
// $name = $row['id'];
// $age = $row['content'];
// echo "Name: $name ";
// echo "Age: $age ";
// echo "\n";
// }
// }
$pdo = null;//关闭连接 } ?></body>
</html>

**********************************************************************************************************************************************************

数据库信息(PDO方式连接数据库)

表名:delphi_test_content

字段:id(主键),content

**********************************************************************************************************************************************************

DEMO效果:

F9运行delphi 按下按钮


按下后,把‘aaaa’这个信息放在POST里传递给http://localhost/DelphiRequest/index.php,该网页获取POST值并且把值保存在表delphi_test_content的ID为2的content里

最终结果


但是如果是中文的话貌似不显示,我也不知道为啥....

后来解决了这个中文显示问题(2016.12.16)

需要添加一行代码

$a=mb_convert_encoding($var_PostAllParma, "UTF-8", "GBK");//delphi7用post传递值给php中文需要字符转码

然后把查询语句的$var_PostAllParma参数更换为$a

$sql ="UPDATE delphi_test_content SET content= '$a' WHERE ID='2'";

最后就解决中文存储到数据库的问题~

谢谢观看~

http://blog.csdn.net/s371795639/article/details/53640483

Delphi通过POST传递参数给PHP的更多相关文章

  1. Delphi过程函数传递参数的几种方式

    Delphi过程函数传递参数的几种方式  在Delphi过程.函数中传递参数几个修饰符为Const.Var.Out. 另一种不加修饰符的为默认按值传递参数. 一.默认方式以值方式传递参数 proced ...

  2. 关于Delphi中多线程传递参数的简单问题

    http://bbs.csdn.net/topics/390513469/ unit uThread; interface uses Classes; type Th = class(TThread) ...

  3. Delphi过程函数传递参数的八种方式

    今天一同事问我为什么有些过程函数里面有Var而有些没有,不解,遂到网上百度,得解.快哉,快哉. 在Delphi过程.函数中传递参数几个修饰符为Const.Var.Out.另一种不加修饰符的为默认按值传 ...

  4. 【delphi】Delphi过程、函数传递参数的八种方式

    Delphi过程函数传递参数的八种方式

  5. delphi的一些语法知识 以及参数传递问题,按引用方式传递参数,按值方式传递参数

    //delphi中exit,abort,break,continue 的区别 exit: 退出函数体abort: 遇到异常,安静处理,就是不显示不提示break: 退出当前循环体,包括for ,whi ...

  6. Vue 给子组件传递参数

    Vue 给子组件传递参数 首先看个例子吧 原文 html <div class="container" id="app"> <div clas ...

  7. [转] C++的引用传递、指针传递参数在java中的相应处理方法

    原文出处:[http://blog.csdn.net/conowen/article/details/7420533] 首先要明白一点,java是没有指针这个概念的. 但是要实现C++的引用传递.指针 ...

  8. 记一次WinForm程序中主进程打开子进程并传递参数的操作过程(进程间传递参数)

    目标:想在WinForm程序之间传递参数.以便子进程作出相应的处理. 一种错误的方法 父进程的主程序: ProcessStartInfo psi = new ProcessStartInfo(); p ...

  9. 在 Angularjs 中 ui-sref 和 $state.go 如何传递参数

    1 ui-sref.$state.go 的区别 ui-sref 一般使用在 <a>...</a>: <a ui-sref="message-list" ...

随机推荐

  1. P3799 妖梦拼木棒 (组合数学)

    题目背景 上道题中,妖梦斩了一地的木棒,现在她想要将木棒拼起来. 题目描述 有n根木棒,现在从中选4根,想要组成一个正三角形,问有几种选法? 输入输出格式 输入格式: 第一行一个整数n 第二行n个整数 ...

  2. Vmware error:无法获得 VMCI 驱动程序的版本: 句柄无效。

    error:无法获得 VMCI 驱动程序的版本: 句柄无效.驱动程序“vmci.sys”的版本不正确.请尝试重新安装 VMware Workstation.开启模块 DevicePowerOn 的操作 ...

  3. LA 2218 半平面交

     题目大意:n名选手参加铁人三项赛,比赛按照选手在三个赛段中所用的总时间排定名次.已知每名选手在三个项目中的速度Ui.Vi.Wi.问对于选手i,能否通过适当的安排三个赛段的长度(但每个赛段的长度都不能 ...

  4. ElasticSearch集群状态查看命令大全

    Elasticsearch中信息很多,同时ES也有很多信息查看命令,可以帮助开发者快速查询Elasticsearch的相关信息. _cat $ curl localhost:9200/_cat =^. ...

  5. mysql合并和时间函数

    sql:利用group_concat()方法,参数为需要合并的字段,合并的字段分隔符默认为逗号,可通过参数separator指定,该方法往往配合group by 一起使用.利用group_concat ...

  6. Day 3 网络基础

    网络基础 一.什么是互联网协议及为何要有互联网协议 ? 互联网协议:指的就是一系列统一的标准,这些标准称之为互联网协议.互联网的本质就是一系列的协议,总称为‘互联网协议’(Internet Proto ...

  7. grequests----golang的requests库

    github.com/levigross/grequests: A Go "clone" of the great and famous Requests library 特点: ...

  8. js Math [ 随机数、绝对值、四舍五入、进一取整、舍去取整、最大值、最小值、圆周率 ]

    <script> /* 数学对象:Math */ with (document) { write('<br>-3.5的绝对值:'+Math.abs(-3.5)); write( ...

  9. python学习之-requests模块基础

    安装版本:2.18 模块导入:import requests l  发送请求 发送GET请求: 获取GITHUB的公共时间线 r = requests.get(url='https://api.git ...

  10. openssl搭建双向认证https

    http://www.barretlee.com/blog/2015/10/05/how-to-build-a-https-server/ http://blog.163.com/fangjinbao ...