how to update value that is stored as an array

One last desperate attempt to solve this.
For firstChoice and secondChoice, these values are entered from a form and show up in the column seperated by commas for example first choice could be “Tennis, Netball” and second “Football, Swimming, Badminton”.
There is a page that shows all the rows in the database, with the buttons “edit” and “delete” next to them. Delete works fine. Edit brings up the form again and the user inputs the information again and this new info should update the corresponding row in the database. But only the values that aren’t checkboxes get updated properly, and the checkbox values get updated as NULL
I can update the name values but not the checkboxes. Any help? I will post how I inserted them in the first place if it helps.
[php]$action = isset( $_POST[‘action’] ) ? $_POST[‘action’] : “”;
if($action == “update”){
$query = “UPDATE table1
SET userID = :userID, name = :name, firstChoice = :firstChoice, secondChoice = :secondChoice
WHERE userID = :userID”;

$stmt = $con->prepare($query);
$stmt->bindParam(’:userID’, $_POST[‘userID’]);
$stmt->bindParam(’:name’, $_POST[‘name’]);
$stmt->bindParam(’:firstChoice’, $_POST[‘firstChoice’]);
$stmt->bindParam(’:secondChoice’, $_POST[‘secondChoice’]);
$stmt->bindParam(’:id’, $_POST[‘id’]);


echo “Updated!”;
}catch(PDOException $exception){ //to handle error
echo "Error: " . $exception->getMessage();
try {

$query = “select userID, name, firstChoice, secondChoice from table1 where id = ? limit 0,1”;
$stmt = $con->prepare ($query);
$stmt->bindParam(‘1’, $_REQUEST[‘id’]);
$row = $stmt->fetch(PDO::FETCH_ASSOC);

$userID = $row[‘userID’];
$name = $row[‘name’];
$firstChoice = $row[‘firstChoice’];
$secondChoice = $row[‘secondChoice’];
$id = $row[‘id’];

}catch(PDOExcepton $exception) {
echo "Error: " . $exception->getMessage();


this is the code from the page that inserts the data that stores them as arrays
[php]if (isset($_POST[‘firstChoice’]) && is_array($_POST[‘firstChoice’])) {
$firstChoiceCB = join (’, ', $_POST[‘firstChoice’]);
else $firstChoiceCB = ‘’;[/php]

Do your checkboxes have square brackets like this:




Some more info: [php][/php]


function array_change_key(&$array, $old_key, $new_key)
$array[$new_key] = $array[$old_key];


Sponsor our Newsletter | Privacy Policy | Terms of Service