2

Hye guys,

I really need help .. I manage to submit this value into DB but it only submit one, not all values. Below I attached the example. I had enter dd, 55 but in DB only received 55 I had enter dd, 55 but in DB only received 55

Here is what i have done. I have this html textarea : <td><textarea class="form-control" name="d3_CA[]"></textarea></td>

Then when I click on submit button this how i handle :

if(isset($_POST['save-report'])){
 foreach($_POST['d3_CA'] as $value)
 {
  $report->d3_CA = $value;
  echo $report->d3_CA;
 }

}

if($report->registerD3()){

  $successMSG ="Success ! Report <span style='color:red;'>" 
  .$_POST['reportNo']. "</span> has been created. ";
  }
  else{
    $errMSG = "Opps ! problem..";
  }

it show correct value when i'm echoing. Then i want to submit it into DB, this what i do :

function registerD3(){
    $query2 = "INSERT INTO " . $this->table_d3 . "
            SET d3_CA=:d3_CA";

    $stmt = $this->conn->prepare($query2);

    $stmt->bindParam(":d3_CA", $this->d3_CA);
    echo $this->d3_CA;
    if($stmt->execute()){
        return true;
    }
    else{
        return false;
    }   
}

1 Answer 1

2
if(isset($_POST['save-report'])){
 foreach($_POST['d3_CA'] as $value)
 {
  $report->d3_CA = $value;
  echo $report->d3_CA;
if($report->registerD3()){

  $successMSG ="Success ! Report <span style='color:red;'>" 
  .$_POST['reportNo']. "</span> has been created. ";
  }
  else{
    $errMSG = "Opps ! problem..";
  }
 }

}

the problem is at the end one value is being stored in $report->d3_CA, and the echo prints the correct result is because its inside the loop, print it outside and you will get the last value only, so use the above code and it will solve your problem

Sign up to request clarification or add additional context in comments.

5 Comments

Exprator ; you means like this ? foreach($_POST['d3_CA'] as $value) { $report->d3_CA = $value; } echo $report->d3_CA;
if i echo outside the foreach it still store only one value inside DB
Nice Exprator ! manage to submit it ! you saved my day man ! thank you
glad could help bro :)
Exprator , now i having this problem .. i'm using your code and change it to this, because i have another textarea/field. When I insert on 1st row -"a b" , 2nd row "c d". When i check in DB i saved like this 1st row "a d", 2nd row "c d" which is not correct. foreach($_POST['d3_CA'] as $valueX){ $report->d3_CA = $valueX; foreach ($_POST['d3_Resp'] as $key => $valueA) { $report->d3_Resp = $valueA; } $report->registerD3(); }

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.