I am trying to import data from Excel to Mysql database
Here is my code:
C# part:
private void Button_Click_1(object sender, RoutedEventArgs e)
{
string putanjaExH = tbH.Text;
string putanjaExE = tbE.Text;
if (putanjaExH != "")
{
var wbh = new XLWorkbook(putanjaExH);
var wsh = wbh.Worksheet("Sheet1");
bool ide = true;
int ih = 5;
while (ide)
{
HttpWebRequest httpWReq = (HttpWebRequest)WebRequest.Create("http://admin.apartman-donat.com/refu.php");
ASCIIEncoding encoding = new ASCIIEncoding();
string postData = "insert into refh (Gizrade, Investitor, Radni_Zadatak, Predmet_ projekta, Vrsta_projekta_K, Vrsta_projekta_O) values (N'" + wsh.Cell(ih, 1).Value.ToString().Replace(".", "") + "', N'" + wsh.Cell(ih, 2).Value + "', N'" + wsh.Cell(ih, 3).Value + "', N'" + wsh.Cell(ih, 4).Value + "', N'" + wsh.Cell(ih, 5).Value + "', N'" + wsh.Cell(ih, 6).Value + "')";
byte[] data = encoding.GetBytes(postData);
httpWReq.Method = "POST";
httpWReq.ContentLength = data.Length;
using (Stream newStream = httpWReq.GetRequestStream())
{
newStream.Write(data, 0, data.Length);
}
WebResponse response = httpWReq.GetResponse();
Console.WriteLine(((HttpWebResponse)response).StatusDescription);
Stream dataStream = response.GetResponseStream();
StreamReader reader = new StreamReader(dataStream);
string responseFromServer = reader.ReadToEnd();
MessageBox.Show(responseFromServer);
reader.Close();
dataStream.Close();
response.Close();
ih = ih + 1;
if (wsh.Cell(ih,1).Value=="")
{
ide = false;
}
}
}
this.Close();
}
PHP part:
<?php
$con = mysql_connect("localhost","test_ref","test");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("refh", $con);
$sql='$_POST[httpWReq]'
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
echo "1 record added";
mysql_close($con);
?>
response is:
lt;br> Parse error</br> : Syntax error: unexpected T_IF in .....
Could someone tell me what am I doing wrong?????