PHP和C#连接 [英] php and c# connection

查看:113
本文介绍了PHP和C#连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的C#代码是

my c# code is

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Net;
using System.IO;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            
            HttpWebRequest httpWReq =
    (HttpWebRequest)WebRequest.Create("http://localhost/m.php");

ASCIIEncoding encoding = new ASCIIEncoding();
string postData =textBox1.Text;
byte[] data = encoding.GetBytes(postData);

httpWReq.Method = "POST";
httpWReq.ContentLength = data.Length;

using (Stream newStream = httpWReq.GetRequestStream())
{
    newStream.Write("postData");
}
        }
    }
}


我的php代码是


My php code is

$con = mysql_connect("localhost","root","");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("data", $con);

$sql="INSERT INTO Persons (Name)
VALUES
('$_POST[httpWReq]')";

if (!mysql_query($sql,$con))
  {
  die('Error: ' . mysql_error());
  }
echo "1 record added";

mysql_close($con);
?>


此行中的php代码有错误,任何人都可以解决此错误吗?


There is mistake in php code in this line can any one solve this mistake??

$sql="INSERT INTO Persons (Name)
VALUES
('$_POST[httpWReq]')";

推荐答案

con = mysql_connect( localhost" root" "); 如果(!
con = mysql_connect("localhost","root",""); if (!


con) { die(' 无法连接:'.mysql_error()); } mysql_select_db("
con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("data",


con);


这篇关于PHP和C#连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆