Trying to POST to PHP to update database.
If I do a single parameter it works fine but if I try two parameters it is not working.
How do I post with two parameters?
VisualBasic Code
Dim dateTime As DateTime = ReturnAsDateTime(thedate, thetime)
Dim dateformat2 As String = "M/d/yyyy HH:mm"
Dim dateformat3 As String = dateTime.ToString(dateformat2)
Dim StudentNOString As String = thestudent.Number.ToString()
Dim upString As String = "future01=" & dateformat3 & "StudentNumber=" & StudentNOString
System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12
Dim request As WebRequest = WebRequest.Create("https://example.com/tofilePHPfile.php")
request.Method = "POST"
Dim byteArray As Byte() = Encoding.UTF8.GetBytes(upString)
request.ContentType = "application/x-www-form-urlencoded"
request.ContentLength = byteArray.Length
Dim dataStream As Stream = request.GetRequestStream()
dataStream.Write(byteArray, 0, byteArray.Length)
dataStream.Close()
Dim response As WebResponse = request.GetResponse()
dataStream = response.GetResponseStream()
Dim reader As New StreamReader(dataStream)
Dim responseFromServer As String = reader.ReadToEnd()
reader.Close()
dataStream.Close()
response.Close()
MsgBox(responseFromServer)
PHP Code
<?php
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
if (isset ($_POST["future01"]) && isset ($_POST["StudentNumber"])){
$future01 = $_POST["future01"];
$StudentNumber = $_POST["StudentNumber"];
} else {
$future01 = "testfortestfortest";
$StudentNumber = "1";
echo "not working";
}
$stmt = $conn->prepare("UPDATE pushtable SET future01=? WHERE StudentNumber=?");
$stmt->bind_param('ss', $future01,$StudentNumber);
$stmt->execute();
echo $future01;
//echo $StudentNumber;
echo "New records created successfully";
$stmt->close();
$conn->close();
?>
There is something wrong with this line I think as the PHP is not posting it correctly.
Dim upString As String = "future01=" & dateformat3 & "StudentNumber=" & StudentNOString
I have tried dozens of different ways and tried to search for my problem but I cannot seem to find an answer. The PHP works perfectly well from IOS objective-c code. So, I think my problem is in the Visual Basic Code.
future01 and StudentNumber are not being recognized individually when POST occurs.
These are some of the pages I have looked at:
How to send and recieve data from Visual Basic to PHP?
https://www.informit.com/articles/article.aspx?p=131236&seqNum=7
Multiple key/value pairs in HTTP POST where key is the same name
How can i send multiple variables from vb.net to php via post method?
https://en.wikipedia.org/wiki/POST_(HTTP)#Use_for_submitting_web_forms