I have a c# application that needs to send and retrieve using a PHP file. This PHP file then communicates with the database that the application uses for its data. My problem is, I don't know how to send and get array data between PHP and C#. Below is my code which only process one data, the student_id.
I tried finding tutorials and solution, and even API's but none could give the exact help I need.
Here is my PHP code:
class CaptureForm{
////LOCAL FUNCTION [->]
private function query($sql, $arg, $fetch = false){
require "config.php";
$q = $db->prepare($sql);
$q->execute($arg);
return $fetch ? $q->fetch(2) : $q;
}
private function getStud($stud_no){
return $this->query("SELECT stud_id FROM tbl_students WHERE stud_id COLLATE latin1_bin LIKE ?", array($stud_no), true)["stud_id"];
}
////LOCAL FUNCTION [<-]
public function ShowStud($stud_no){
if(empty($stud_no)) return "ERROR:MISSING_PARAMETERS";
return $this->query("SELECT first_name FROM tbl_students WHERE stud_id = ?", array($this->getStud($stud_no)), true)["first_name"];
}
////USER FUNCTION [->]
public function CheckWork($stud_no){ //=login
if(empty($stud_no)) return "ERROR:MISSING_PARAMETERS";
return "OK:LOGGED_IN";
}
and this is my C# code:
private void btn_in_Click(object sender, EventArgs e)
{
if (Execute("CheckWork", "stud_no=" + stud_num.Text) == 1)
{
stud_no = stud_num.Text; //To pass it to any other froms (=global)
//same for pass
WebClient fetchInfo = new WebClient();
string studno = fetchInfo.DownloadString("http://localhost/server_api/clog.php?action=showStud&stud_no=" + stud_no);
if (studno == "Michelle")
{
MessageBox.Show("You are logged in! Yay!", "Logged in", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
MessageBox.Show("You are logged in!", "Logged in", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
}
Both codes are working very well but as I said, can only process one data. I expect to have an array of data to be sent to PHP then to the database and back from PHP to C# then output it as broken down strings. You can send the answer if you know or any other solution/tutorial that you can give. Thank you very much!!