Insert doubt with while

Asked

Viewed 77 times

0

I have this while that brings me all the vendors I want in an array, in which I can edit their name, my problem is that I want to make an index of these values in another table, but I have no idea how I would do that, since the "name" to do the post would be the same for everyone. Would anyone have any suggestions?

edited: with the help of our friend we arrived at this result but it is not taking the values and playing in the variables #id... it would have to be $_POST['supplier#3'] for example

if (array_key_exists("novoRecorrente", $_POST)){ 

$names = []; 
foreach ($_POST as $key => $value) { 
if (count(explode("#", $key)) == 2) { 
$names[explode("#", $key)[1]] = $key; 
} 
} 
foreach ($names as $key => $value) { 

$stmt = $mysqli->prepare("INSERT INTO contaspagar (contaspagar_fornecedor, contaspagar_valor, contaspagar_dv, contaspagar_status) VALUES (?,?,?,?)"); 
$stmt->bind_param("ssss", $_POST['fornecedor'],$_POST['valor'],$_POST['dataV'],$_POST['status']);
$stmt->execute(); 
} 
$stmt->close();
  • I think the ideal would be to create a table to list all suppliers and another page to edit them

  • is what I thought because this list can be dynamic, increasing based on the registration that comes from select

  • Yes, assemble a table through PHP or some Datatables type lib to create a list with suppliers, each vendor will have a link to a page that loads the vendor that was selected

  • but the idea is to edit all at once, because it will be a process done several times, in the example I put only the name of the supplier but will pull together other information

  • ok, Voce can concatenate the object id in the name name="nome_<?php echo $variavel['id'] ?>" so Voce treats the names then taking the id. It’s an idea

  • the idea is good, just a doubt.. how would I do from there the Insert in the bank taking these two parameters? ta kind of confusing for me

  • you can give a explode in name, like this explode('_', $variavel), so you separate the id from the name. That way you want it will take work!

  • i was able to put the -id in the name... in the file that I add in the bank if I add the parameters with the - and the number is adding, I don’t know what the loop would look like if it would bring the ID instead of setting the id number manually

Show 4 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.