Please be gentle with me, I'm very new to PHP and MySQL.
I'm trying to insert and retrieve data to and from MySQL using PDO.
here is the HTML form which sends the data to my PHP using POST
<FORM ACTION="index.php" METHOD=POST>
Update# :
<INPUT TYPE=TEXT NAME="update_num" align="left" LENGTH=2 required >
<P>
<P>
ETO :
<INPUT TYPE=TEXT NAME="eto" LENGTH=30 >
</P>
<P>
CAD# :
<INPUT TYPE=TEXT NAME="cad" LENGTH=30 >
</P>
<p>
CMS:
</p>
<h6>Hold Down control(CTRL) key to select multiple CMSs</h6>
<SELECT NAME = "cms[]" multiple>
<option></option>>
<option>#1</option>>
<option>#2</option>>
<option>#3</option>>
<option>#4</option>>
</SELECT>
</p>
<INPUT TYPE=SUBMIT VALUE="Submit Form" align="center">
</FORM>
</INPUT>
I made the modifications according to this post from Stackoverflow : Getting All $_POST From Multiple Select Value
My PHP code looks like this:
$sql = "INSERT INTO dutypage (update_num, eto, cad, cms) VALUES (:update_num, :eto, :cad, :cms)";
$stmt = $conn->prepare($sql);
$stmt->bindParam(':update_num', $_POST['update_num']);
$stmt->bindParam(':eto', $_POST['eto']);
$stmt->bindParam(':cad', $_POST['cad']);
$stmt->bindParam(':cms', $_POST['cms']);
$stmt->execute();
my data get successfully inserted but the cms column now just displays Array
I use the following code to retrieve the data
$query="SELECT cms FROM dutypage ORDER BY dateOf DESC";
$data=$conn->query($query);
$result = $data->fetchAll(PDO::FETCH_ASSOC);
var_dump($result);
foreach ($result as $output) {
echo $output['cms'];
echo "<br>";
}
and I only get this:
array(1) { [0]=> array(1) { ["cms"]=> string(5) "Array" } } Array
Are my selected options in the form actually being passed into the array in the MySQL?