0

So i have a page that looks like this (After i filled it in)

How the page looks

And i have a database table that looks like this:

what the database looks like

Now, after i press the button: "Add to summary", i would like the info to be inserted in the database like this:

What the database should look like

I did this before but then with 2 arrays, and now i have 3. Code it worked with:

    $train_id = $_POST['train_id'];
    $user_id = $_POST['user_id'];
        foreach (array_combine($train_id, $user_id) as $train_id => $user_id){
            $update_axle = $database->summary_add($train_id, $user_id);
        }

But now, i have ['summary_name'] extra.

What my table looks like:

<input type="text" name="summary_name[]" id="summary_name" required placeholder="Enter summary name">
<input type='hidden' name='user_id[]' value='<?php echo $_GET['user_id']?>'>
<input type='hidden' name='train_id[]' value='<?php echo $selected_train['train_id']?>'>

These give the correct value. Then when you press the Add to summary button, you will go to the page that should insert the values:

Function:

function create_summary($train_id, $summary_name, $user_id) {
            $sql = "INSERT INTO summary "
        . "(summary_id, user_id, summary_name, train_id)"
        . "VALUES (summary_id, :user_id, :summary_name, :train_id) ";
            $sth = $this->pdo->prepare($sql);
            $sth->bindParam(':user_id', $_POST['user_id'], PDO::PARAM_INT);
            $sth->bindParam(':summary_name', $_POST['summary_name'], PDO::PARAM_STR);
            $sth->bindParam(':train_id', $_POST['train_id'], PDO::PARAM_INT);
            $sth->execute();
    }
Mitch
  • 1,173
  • 1
  • 10
  • 31

0 Answers0