0

I have an client app written on c#, from which i need to insert information, using api interface. I trying to make that api, but i'm really newbie in web development. From what i understand, i need to make a POST (for better security) x-www-form-urlencoded request to my web api script. I have a post parameters like this:

client_id=1234&client_version=4&data_key[0]=encryptionkey1&data_selenium_browser[0]=firefox46&data_driver_path[0]=c:\user\appdata\client\drivers\s_driver1.exe&data_key[1]=encryptionkey2&data_selenium_browser[1]&data_driver_path[1]=c:\user\appdata\client\drivers\s_driver2.exe

There can be any amount of data_key and data_selenium_browser and data_driver_path.

So i parse all that parameters, and now i need to insert an array of data_key and data_selenium_browser and data_driver_path for each user id.

I have question, what would be better way to pass array of parameters and how can i store it inside mysql? Currently from what i have thought, i can do a separate table like this:

CREATE TABLE clients_data (
   client_id int ,
   data_key varchar(32),
   data_selenium_browser varchar(32),
   data_driver_path TEXT
);

So the client_id is not unique, i assume i must insert a multiple records for each user, with those parameters, and do LEFT JOIN or something like that, to select all that columns, when displaying user info?

0

1 Answer 1

1

Use a foreach loop. Here's how to do it using a PDO prepared statement.

$update_stmt = $conn->prepare("
    INSERT INTO clients_data (client_id, data_key, data_selenium_browser, data_driver_path)
    VALUES (:id, :key, :browser, :path)");
$update_stmt->bindParam(":id", $id);
$update_stmt->bindParam(":key", $key);
$update_stmt->bindParam(":browser", $browser);
$update_stmt->bindParam(":path", $path);
$id = $_GET['client_id'];
foreach ($_GET['data_key'] AS $index => $key) {
    $browser = $_GET['data_selenium_browser'][$index];
    $path = $_GET['data_driver_path'][$index];
    $update_stmt->execute();
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.