I have a table in which two text fields and one input text field. A query is created new row, and if there is one, just update.
if (isset($_POST['submit'])) {
$text = !empty($_POST['text']) ? $_POST['text'] : null;
foreach ($text as $idt => $pages) {
if ($pages != NULL) {
$todb = $mysqli->query('INSERT INTO extendtovar (book_id, pages)
VALUES ("' . $idt . '", "' . $pages . '")
ON DUPLICATE KEY UPDATE pages = "' . $pages . '"');
}
}
}
$todb = $mysqli->query('SELECT
nalvmag.id AS id,
nalvmag.name AS name,
extendtovar.book_id AS id2,
extendtovar.pages AS pages
FROM nalvmag LEFT JOIN extendtovar
ON nalvmag.id = extendtovar.book_id
WHERE nalvmag.remainder > 0
ORDER BY name ASC');
echo '<table class="raz">';
while ($row = $todb->fetch_array())
{ echo '<tr><td>'.$row[id].'</td>';
echo '<td>'.$row[name].'</td>';
echo '<td><input type="text" name="text['.$row[id].']" value="'.$row[pages].'" maxlength="5" size="6"><br></td></tr>';
}
echo '</table>';
echo'<button type="submit" name="submit">Submit</button></form>';
}
But now I want to add one more input text field
echo $row[id];
echo row[name];
echo '<input type="text" name="text['.$row[id].']" value="'.$row[pages].'" maxlength="5" size="6">
echo '<input type="text" name="text2['.$row[id].']" value="'.$row[pages2].'" maxlength="5" size="6">
and when i update php code to
if (isset($_POST['submit'])) {
$text = !empty($_POST['text']) ? $_POST['text'] : null;
foreach ($text as $idt => $pages) {
if ($pages != NULL) {
$todb = $mysqli->query('INSERT INTO extendtovar (book_id, pages, pages)
VALUES ("' . $idt . '", "' . $pages . '", "' . $pages2 . '")
ON DUPLICATE KEY UPDATE pages = "' . $pages . '", pages2 = "' . $pages2 . '"');
}
}
}
field pages2 not update.
I can not understand how to properly change foreach
and form a request