php and mysql insert into multiple tables from one form












0















I am creating a simple site to keep records of users, customers, suppliers, etc.



I have created the forms to register clients and users using single forms capturing data through $ _POST form method



So far I have not had problems since the INSERTS are done on singles table wich PK is an AutoIncremented field



In the code shown below, my goal is to let users create a vendor (name, phone number, email, address) as well as asign 1 or many vendor-category. This information is contained in one form



vendors, vendors-categories, users etc are stored in a mysql database with the structure shown in attached file



structure



There is something wrong about my code after succesfully create vendor and i am not sure how to solve the part that manages insertions in the join table (tblprovxrubro)



Code



<?php

session_start();
//available for admin, power-users and role-4
if ($_SESSION['rol'] ==2) {
header("location: ./");
}
include "../conexion.php";


if (!empty($_POST)) {
$alert='';
if (empty($_POST['razonSocial'])|| empty($_POST['email'])) {
$alert='<p class="msg_error">Vendor name and email must not be blank.</p>';

}else{


$razonSocial = $_POST['razonSocial'];
$email = $_POST['email'];
$domicilio = $_POST['domicilio'];
$telefono = $_POST['telefono'];
$usuario_id = $_SESSION['iduser'];

$query = mysqli_query($conection,"SELECT * FROM tblprov WHERE razonSocial = '$razonSocial'");
$result = mysqli_fetch_array($query);

if ($result >0)
{
$alert='<p class="msg_error">vendor already exists.</p>';
}else{
$query_insert = mysqli_query($conection, "INSERT INTO tblprov(razonSocial, numero, domicilio, email, idUsuario)
VALUES('$razonSocial','$telefono','$domicilio','$email', '$usuario_id')");

if ($query_insert)
{
$alert='<p class="msg_save">Vendor created succesfully.</p>';

//Once vendor is created i need his ID in order to insert in table
//tblprovxrubro as many records as vendor-types selected in form

//Not sure about how to achieve this

$queryBuscaprov = mysqli_query($conection, "SELECT id FROM tblprov WHERE razonSocial = '$razonSocial'");
$result_prov = mysqli_fetch_array($queryBuscaProv);
$idProv = $result_prov['id'];

foreach ($_POST['idRubro'] as $opcionSeleccionada)
{
//This INSERT should execute as many times as vendor-types selected in form
$query2 = mysqli_query($conection, "INSERT INTO tblprovxrubro (idRubro, idProv) VALUES ('$opcionSeleccionada', '$idProv')");
}
}else{
$alert='<p class="msg_error">Error creating vendor.</p>';
}
}
}
mysqli_close($conection);
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<?php include "includes/scripts.php"; ?>
<title>Registro de Proveedores</title>

</head>
<body>
<?php include "includes/header.php"; ?>
<section id="container">
<div class="form_register" name="form_register">
<h1><i class="fas fa-building"></i> Vendor List</h1>
<hr>

<form action="" method="post" class="form_register">

<div class="alert"><?php echo isset($alert) ? $alert : ''; ?></div>
<label for="razonSocial">Razón Social</label>
<input type="text" name="razonSocial" id="razonSocial" placeholder="Razón Social">
<label for="telefono">Número Telefónico</label>
<input type="text" name="telefono" id="telefono" placeholder="Número Telefónico">
<label for="domicilio">Domicilio</label>
<input type="text" name="domicilio" id="domicilio" placeholder="Domicilio">
<label for="email">Email</label>
<input type="text" name="email" id="email" placeholder="Email">

<?php
$query_rubro = mysqli_query($conection,"SELECT * FROM tblrubros");
mysqli_close($conection);
$result_rubro = mysqli_num_rows($query_rubro);
?>
<select name="rubro" id="rubro" multiple size="12">

<?php
if($result_rubro > 0)
{
while ($rubro = mysqli_fetch_array($query_rubro))
{
?>
<option value="<?php echo $rubro["idRubro"]; ?>"><?php echo $rubro["rubroDescripcion"] ?></option>
<?php
}
}
?>
</select>
<p>press Ctrl in order to select multiple options.</p>
<button name="submit" type="submit" class="btn_save"><i class="fas fa-save"></i> Crear Proveedor</button>
</form>
</div>
</section>

<?php include "includes/footer.php"; ?>
</body>
</html>


conection.php



<?php

$host = 'localhost';
$user = 'root';
$password = 'mypass';
$db = 'compras';

$conection = @mysqli_connect($host,$user,$password,$db);
mysqli_set_charset($conection,"utf8");

if(!$conection){
echo "connection error";
}

?>









share|improve this question


















  • 1





    Hugo please use prepared statements, you code right now is prone to sql injection.

    – Hackerman
    Nov 20 '18 at 21:25













  • can you expand on "something wrong"? What are the results/errors?

    – danblack
    Nov 20 '18 at 21:33











  • will come back in a while and answer this

    – Hugo Jastrzebski
    Nov 20 '18 at 21:47








  • 1





    first you need to prone your results against sql injection. Secondly instead of using else if statement to check if your first query is ok before applying the second one. I suggest you use the transaction mechanism with multi queries that only commit your queries if all are correct, If not you rollback. multi_queries, transaction

    – Loic L.
    Nov 20 '18 at 21:57
















0















I am creating a simple site to keep records of users, customers, suppliers, etc.



I have created the forms to register clients and users using single forms capturing data through $ _POST form method



So far I have not had problems since the INSERTS are done on singles table wich PK is an AutoIncremented field



In the code shown below, my goal is to let users create a vendor (name, phone number, email, address) as well as asign 1 or many vendor-category. This information is contained in one form



vendors, vendors-categories, users etc are stored in a mysql database with the structure shown in attached file



structure



There is something wrong about my code after succesfully create vendor and i am not sure how to solve the part that manages insertions in the join table (tblprovxrubro)



Code



<?php

session_start();
//available for admin, power-users and role-4
if ($_SESSION['rol'] ==2) {
header("location: ./");
}
include "../conexion.php";


if (!empty($_POST)) {
$alert='';
if (empty($_POST['razonSocial'])|| empty($_POST['email'])) {
$alert='<p class="msg_error">Vendor name and email must not be blank.</p>';

}else{


$razonSocial = $_POST['razonSocial'];
$email = $_POST['email'];
$domicilio = $_POST['domicilio'];
$telefono = $_POST['telefono'];
$usuario_id = $_SESSION['iduser'];

$query = mysqli_query($conection,"SELECT * FROM tblprov WHERE razonSocial = '$razonSocial'");
$result = mysqli_fetch_array($query);

if ($result >0)
{
$alert='<p class="msg_error">vendor already exists.</p>';
}else{
$query_insert = mysqli_query($conection, "INSERT INTO tblprov(razonSocial, numero, domicilio, email, idUsuario)
VALUES('$razonSocial','$telefono','$domicilio','$email', '$usuario_id')");

if ($query_insert)
{
$alert='<p class="msg_save">Vendor created succesfully.</p>';

//Once vendor is created i need his ID in order to insert in table
//tblprovxrubro as many records as vendor-types selected in form

//Not sure about how to achieve this

$queryBuscaprov = mysqli_query($conection, "SELECT id FROM tblprov WHERE razonSocial = '$razonSocial'");
$result_prov = mysqli_fetch_array($queryBuscaProv);
$idProv = $result_prov['id'];

foreach ($_POST['idRubro'] as $opcionSeleccionada)
{
//This INSERT should execute as many times as vendor-types selected in form
$query2 = mysqli_query($conection, "INSERT INTO tblprovxrubro (idRubro, idProv) VALUES ('$opcionSeleccionada', '$idProv')");
}
}else{
$alert='<p class="msg_error">Error creating vendor.</p>';
}
}
}
mysqli_close($conection);
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<?php include "includes/scripts.php"; ?>
<title>Registro de Proveedores</title>

</head>
<body>
<?php include "includes/header.php"; ?>
<section id="container">
<div class="form_register" name="form_register">
<h1><i class="fas fa-building"></i> Vendor List</h1>
<hr>

<form action="" method="post" class="form_register">

<div class="alert"><?php echo isset($alert) ? $alert : ''; ?></div>
<label for="razonSocial">Razón Social</label>
<input type="text" name="razonSocial" id="razonSocial" placeholder="Razón Social">
<label for="telefono">Número Telefónico</label>
<input type="text" name="telefono" id="telefono" placeholder="Número Telefónico">
<label for="domicilio">Domicilio</label>
<input type="text" name="domicilio" id="domicilio" placeholder="Domicilio">
<label for="email">Email</label>
<input type="text" name="email" id="email" placeholder="Email">

<?php
$query_rubro = mysqli_query($conection,"SELECT * FROM tblrubros");
mysqli_close($conection);
$result_rubro = mysqli_num_rows($query_rubro);
?>
<select name="rubro" id="rubro" multiple size="12">

<?php
if($result_rubro > 0)
{
while ($rubro = mysqli_fetch_array($query_rubro))
{
?>
<option value="<?php echo $rubro["idRubro"]; ?>"><?php echo $rubro["rubroDescripcion"] ?></option>
<?php
}
}
?>
</select>
<p>press Ctrl in order to select multiple options.</p>
<button name="submit" type="submit" class="btn_save"><i class="fas fa-save"></i> Crear Proveedor</button>
</form>
</div>
</section>

<?php include "includes/footer.php"; ?>
</body>
</html>


conection.php



<?php

$host = 'localhost';
$user = 'root';
$password = 'mypass';
$db = 'compras';

$conection = @mysqli_connect($host,$user,$password,$db);
mysqli_set_charset($conection,"utf8");

if(!$conection){
echo "connection error";
}

?>









share|improve this question


















  • 1





    Hugo please use prepared statements, you code right now is prone to sql injection.

    – Hackerman
    Nov 20 '18 at 21:25













  • can you expand on "something wrong"? What are the results/errors?

    – danblack
    Nov 20 '18 at 21:33











  • will come back in a while and answer this

    – Hugo Jastrzebski
    Nov 20 '18 at 21:47








  • 1





    first you need to prone your results against sql injection. Secondly instead of using else if statement to check if your first query is ok before applying the second one. I suggest you use the transaction mechanism with multi queries that only commit your queries if all are correct, If not you rollback. multi_queries, transaction

    – Loic L.
    Nov 20 '18 at 21:57














0












0








0








I am creating a simple site to keep records of users, customers, suppliers, etc.



I have created the forms to register clients and users using single forms capturing data through $ _POST form method



So far I have not had problems since the INSERTS are done on singles table wich PK is an AutoIncremented field



In the code shown below, my goal is to let users create a vendor (name, phone number, email, address) as well as asign 1 or many vendor-category. This information is contained in one form



vendors, vendors-categories, users etc are stored in a mysql database with the structure shown in attached file



structure



There is something wrong about my code after succesfully create vendor and i am not sure how to solve the part that manages insertions in the join table (tblprovxrubro)



Code



<?php

session_start();
//available for admin, power-users and role-4
if ($_SESSION['rol'] ==2) {
header("location: ./");
}
include "../conexion.php";


if (!empty($_POST)) {
$alert='';
if (empty($_POST['razonSocial'])|| empty($_POST['email'])) {
$alert='<p class="msg_error">Vendor name and email must not be blank.</p>';

}else{


$razonSocial = $_POST['razonSocial'];
$email = $_POST['email'];
$domicilio = $_POST['domicilio'];
$telefono = $_POST['telefono'];
$usuario_id = $_SESSION['iduser'];

$query = mysqli_query($conection,"SELECT * FROM tblprov WHERE razonSocial = '$razonSocial'");
$result = mysqli_fetch_array($query);

if ($result >0)
{
$alert='<p class="msg_error">vendor already exists.</p>';
}else{
$query_insert = mysqli_query($conection, "INSERT INTO tblprov(razonSocial, numero, domicilio, email, idUsuario)
VALUES('$razonSocial','$telefono','$domicilio','$email', '$usuario_id')");

if ($query_insert)
{
$alert='<p class="msg_save">Vendor created succesfully.</p>';

//Once vendor is created i need his ID in order to insert in table
//tblprovxrubro as many records as vendor-types selected in form

//Not sure about how to achieve this

$queryBuscaprov = mysqli_query($conection, "SELECT id FROM tblprov WHERE razonSocial = '$razonSocial'");
$result_prov = mysqli_fetch_array($queryBuscaProv);
$idProv = $result_prov['id'];

foreach ($_POST['idRubro'] as $opcionSeleccionada)
{
//This INSERT should execute as many times as vendor-types selected in form
$query2 = mysqli_query($conection, "INSERT INTO tblprovxrubro (idRubro, idProv) VALUES ('$opcionSeleccionada', '$idProv')");
}
}else{
$alert='<p class="msg_error">Error creating vendor.</p>';
}
}
}
mysqli_close($conection);
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<?php include "includes/scripts.php"; ?>
<title>Registro de Proveedores</title>

</head>
<body>
<?php include "includes/header.php"; ?>
<section id="container">
<div class="form_register" name="form_register">
<h1><i class="fas fa-building"></i> Vendor List</h1>
<hr>

<form action="" method="post" class="form_register">

<div class="alert"><?php echo isset($alert) ? $alert : ''; ?></div>
<label for="razonSocial">Razón Social</label>
<input type="text" name="razonSocial" id="razonSocial" placeholder="Razón Social">
<label for="telefono">Número Telefónico</label>
<input type="text" name="telefono" id="telefono" placeholder="Número Telefónico">
<label for="domicilio">Domicilio</label>
<input type="text" name="domicilio" id="domicilio" placeholder="Domicilio">
<label for="email">Email</label>
<input type="text" name="email" id="email" placeholder="Email">

<?php
$query_rubro = mysqli_query($conection,"SELECT * FROM tblrubros");
mysqli_close($conection);
$result_rubro = mysqli_num_rows($query_rubro);
?>
<select name="rubro" id="rubro" multiple size="12">

<?php
if($result_rubro > 0)
{
while ($rubro = mysqli_fetch_array($query_rubro))
{
?>
<option value="<?php echo $rubro["idRubro"]; ?>"><?php echo $rubro["rubroDescripcion"] ?></option>
<?php
}
}
?>
</select>
<p>press Ctrl in order to select multiple options.</p>
<button name="submit" type="submit" class="btn_save"><i class="fas fa-save"></i> Crear Proveedor</button>
</form>
</div>
</section>

<?php include "includes/footer.php"; ?>
</body>
</html>


conection.php



<?php

$host = 'localhost';
$user = 'root';
$password = 'mypass';
$db = 'compras';

$conection = @mysqli_connect($host,$user,$password,$db);
mysqli_set_charset($conection,"utf8");

if(!$conection){
echo "connection error";
}

?>









share|improve this question














I am creating a simple site to keep records of users, customers, suppliers, etc.



I have created the forms to register clients and users using single forms capturing data through $ _POST form method



So far I have not had problems since the INSERTS are done on singles table wich PK is an AutoIncremented field



In the code shown below, my goal is to let users create a vendor (name, phone number, email, address) as well as asign 1 or many vendor-category. This information is contained in one form



vendors, vendors-categories, users etc are stored in a mysql database with the structure shown in attached file



structure



There is something wrong about my code after succesfully create vendor and i am not sure how to solve the part that manages insertions in the join table (tblprovxrubro)



Code



<?php

session_start();
//available for admin, power-users and role-4
if ($_SESSION['rol'] ==2) {
header("location: ./");
}
include "../conexion.php";


if (!empty($_POST)) {
$alert='';
if (empty($_POST['razonSocial'])|| empty($_POST['email'])) {
$alert='<p class="msg_error">Vendor name and email must not be blank.</p>';

}else{


$razonSocial = $_POST['razonSocial'];
$email = $_POST['email'];
$domicilio = $_POST['domicilio'];
$telefono = $_POST['telefono'];
$usuario_id = $_SESSION['iduser'];

$query = mysqli_query($conection,"SELECT * FROM tblprov WHERE razonSocial = '$razonSocial'");
$result = mysqli_fetch_array($query);

if ($result >0)
{
$alert='<p class="msg_error">vendor already exists.</p>';
}else{
$query_insert = mysqli_query($conection, "INSERT INTO tblprov(razonSocial, numero, domicilio, email, idUsuario)
VALUES('$razonSocial','$telefono','$domicilio','$email', '$usuario_id')");

if ($query_insert)
{
$alert='<p class="msg_save">Vendor created succesfully.</p>';

//Once vendor is created i need his ID in order to insert in table
//tblprovxrubro as many records as vendor-types selected in form

//Not sure about how to achieve this

$queryBuscaprov = mysqli_query($conection, "SELECT id FROM tblprov WHERE razonSocial = '$razonSocial'");
$result_prov = mysqli_fetch_array($queryBuscaProv);
$idProv = $result_prov['id'];

foreach ($_POST['idRubro'] as $opcionSeleccionada)
{
//This INSERT should execute as many times as vendor-types selected in form
$query2 = mysqli_query($conection, "INSERT INTO tblprovxrubro (idRubro, idProv) VALUES ('$opcionSeleccionada', '$idProv')");
}
}else{
$alert='<p class="msg_error">Error creating vendor.</p>';
}
}
}
mysqli_close($conection);
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<?php include "includes/scripts.php"; ?>
<title>Registro de Proveedores</title>

</head>
<body>
<?php include "includes/header.php"; ?>
<section id="container">
<div class="form_register" name="form_register">
<h1><i class="fas fa-building"></i> Vendor List</h1>
<hr>

<form action="" method="post" class="form_register">

<div class="alert"><?php echo isset($alert) ? $alert : ''; ?></div>
<label for="razonSocial">Razón Social</label>
<input type="text" name="razonSocial" id="razonSocial" placeholder="Razón Social">
<label for="telefono">Número Telefónico</label>
<input type="text" name="telefono" id="telefono" placeholder="Número Telefónico">
<label for="domicilio">Domicilio</label>
<input type="text" name="domicilio" id="domicilio" placeholder="Domicilio">
<label for="email">Email</label>
<input type="text" name="email" id="email" placeholder="Email">

<?php
$query_rubro = mysqli_query($conection,"SELECT * FROM tblrubros");
mysqli_close($conection);
$result_rubro = mysqli_num_rows($query_rubro);
?>
<select name="rubro" id="rubro" multiple size="12">

<?php
if($result_rubro > 0)
{
while ($rubro = mysqli_fetch_array($query_rubro))
{
?>
<option value="<?php echo $rubro["idRubro"]; ?>"><?php echo $rubro["rubroDescripcion"] ?></option>
<?php
}
}
?>
</select>
<p>press Ctrl in order to select multiple options.</p>
<button name="submit" type="submit" class="btn_save"><i class="fas fa-save"></i> Crear Proveedor</button>
</form>
</div>
</section>

<?php include "includes/footer.php"; ?>
</body>
</html>


conection.php



<?php

$host = 'localhost';
$user = 'root';
$password = 'mypass';
$db = 'compras';

$conection = @mysqli_connect($host,$user,$password,$db);
mysqli_set_charset($conection,"utf8");

if(!$conection){
echo "connection error";
}

?>






php mysql insert






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 20 '18 at 21:23









Hugo JastrzebskiHugo Jastrzebski

81




81








  • 1





    Hugo please use prepared statements, you code right now is prone to sql injection.

    – Hackerman
    Nov 20 '18 at 21:25













  • can you expand on "something wrong"? What are the results/errors?

    – danblack
    Nov 20 '18 at 21:33











  • will come back in a while and answer this

    – Hugo Jastrzebski
    Nov 20 '18 at 21:47








  • 1





    first you need to prone your results against sql injection. Secondly instead of using else if statement to check if your first query is ok before applying the second one. I suggest you use the transaction mechanism with multi queries that only commit your queries if all are correct, If not you rollback. multi_queries, transaction

    – Loic L.
    Nov 20 '18 at 21:57














  • 1





    Hugo please use prepared statements, you code right now is prone to sql injection.

    – Hackerman
    Nov 20 '18 at 21:25













  • can you expand on "something wrong"? What are the results/errors?

    – danblack
    Nov 20 '18 at 21:33











  • will come back in a while and answer this

    – Hugo Jastrzebski
    Nov 20 '18 at 21:47








  • 1





    first you need to prone your results against sql injection. Secondly instead of using else if statement to check if your first query is ok before applying the second one. I suggest you use the transaction mechanism with multi queries that only commit your queries if all are correct, If not you rollback. multi_queries, transaction

    – Loic L.
    Nov 20 '18 at 21:57








1




1





Hugo please use prepared statements, you code right now is prone to sql injection.

– Hackerman
Nov 20 '18 at 21:25







Hugo please use prepared statements, you code right now is prone to sql injection.

– Hackerman
Nov 20 '18 at 21:25















can you expand on "something wrong"? What are the results/errors?

– danblack
Nov 20 '18 at 21:33





can you expand on "something wrong"? What are the results/errors?

– danblack
Nov 20 '18 at 21:33













will come back in a while and answer this

– Hugo Jastrzebski
Nov 20 '18 at 21:47







will come back in a while and answer this

– Hugo Jastrzebski
Nov 20 '18 at 21:47






1




1





first you need to prone your results against sql injection. Secondly instead of using else if statement to check if your first query is ok before applying the second one. I suggest you use the transaction mechanism with multi queries that only commit your queries if all are correct, If not you rollback. multi_queries, transaction

– Loic L.
Nov 20 '18 at 21:57





first you need to prone your results against sql injection. Secondly instead of using else if statement to check if your first query is ok before applying the second one. I suggest you use the transaction mechanism with multi queries that only commit your queries if all are correct, If not you rollback. multi_queries, transaction

– Loic L.
Nov 20 '18 at 21:57












0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53401739%2fphp-and-mysql-insert-into-multiple-tables-from-one-form%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53401739%2fphp-and-mysql-insert-into-multiple-tables-from-one-form%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Biblatex bibliography style without URLs when DOI exists (in Overleaf with Zotero bibliography)

ComboBox Display Member on multiple fields

Is it possible to collect Nectar points via Trainline?