我正在尝试将值插入到我从Winform Application创建的测试数据库中。我大部分都在工作,但是当我通过POST请求发送时,总会有一个密钥丢失。
我有一个存储在灯堆上的php文件,并且要插入的相关代码如下:
$CustId = mysqli_real_escape_string($con, $_POST['CustId']);
$LastName = mysqli_real_escape_string($con, $_POST['LastName']);
$FirstName = mysqli_real_escape_string($con, $_POST['FirstName']);
$DOB = mysqli_real_escape_string($con, $_POST['DOB']);
$CustPhone = mysqli_real_escape_string($con, $_POST['CustPhone']);
$LatestToken = mysqli_real_escape_string($con, $_POST['LatestToken']);
$AcntLast4 = mysqli_real_escape_string($con, $_POST['AcntLast4']);
$AuthKey = mysqli_real_escape_string($con, $_POST['AuthKey']);
$sql="INSERT INTO Customer (CustId, LastName, FirstName, DOB, CustPhone,
LatestToken, AcntLast4, AuthKey) VALUES ('$CustId', '$LastName',
'$FirstName', '$DOB', '$CustPhone', '$LatestToken', '$AcntLast4',
'$AuthKey')";
现在在C#Winforms Side上我将以下代码作为按钮事件。注意我已经硬编码了值,因为我不想每次都在文本框中输入它们
string URL = "http://localhost/InsertCustomer.php";
WebClient webClient = new WebClient();
NameValueCollection formData = new NameValueCollection();
formData["CustId"] = "avc7";
formData["LastName"] = "Tired";
formData["FirstName"] = "Iam";
formData["DOB"] = "2009-05-04";
formData["CustPhone"] = "54433454";
formData["LatestToken"] = "85858dgggd"; //We get this from the call
formData["AcntLast4"] = "9874"; //We get this from the call
formData["Authkey"] = "fake"; //This is stored in config file
byte[] responseBytes = webClient.UploadValues(URL, "POST", formData);
string responsefromserver = Encoding.UTF8.GetString(responseBytes);
richTextBox1.Text = responsefromserver;
webClient.Dispose();
现在,当我触发此事件时,它将所有值存储到mysql表中,但#34; AuthKey"除外。
有2张桌子。一个表称为Customer,其结构如下:
CUSTOMER
CustID Primary Key Not null
LastName varchar
FirstName varchar
DOB Date
CustPhone varchar
LatestToken varchar
AuthKey Primary Key Not Null
AcntLast4
还有一个历史记录表
HISTORY
HistoryNum Primary Not Null Auto Increment
TransAmt varchar
Transdate date
TransType varchar
AuthKey varchar
CustId varchar
当我尝试插入如上所示的客户表时,它没有填写" AuthKey"的值。但它确实适用于其他一切。
当我尝试插入历史表时,它不会填充" AuthKey"或" CustId"但它确实适用于其他一切。
某个地方我觉得我搞砸了钥匙。此时可能无法正确建模此数据库,但为什么它会以这种方式运行?我一直在盯着它,尝试几个小小的改动,看它是否修复但我没有成功。这是我的最后一招。感谢另一个注意事项:当我使用mysql在终端中进行查询时,一切都插入就好了。所以我只是不确定这里发生了什么
编辑:我已采取一些措施来缩小问题范围。