-1

I have a form in php wich has some checkboxes named skills[], I want to know how to implode and post the correct way in this code, I was used to the usual msqli or normal post syntax, but now that I made country state city dropdown I can't figure out a way to correctly post it:

<?php
$skills = array('PHP', 'JavaScript', 'jQuery', 'AngularJS');
$commasaprated = implode(',' , $skills);
?>

<?php
//insert.php

if(isset($_POST['country']))
{
    include('database_connection.php');
    $query = "
    INSERT INTO country_state_city_form_data (country, state, city, skills) 
    VALUES(:country, :state, :city, :skills)
    ";
    $statement = $connect->prepare($query);
    $statement->execute(
        array(
            ':country'      =>  $_POST['country'],
            ':state'        =>  $_POST['state'],
            ':city'         =>  $_POST['hidden_city'],
            ':skills'           =>  $_POST['skills'],
        )
    );
    $result = $statement->fetchAll();

    if(isset($result))
    {
        echo 'done';
    }

}

?>
Sunderam Dubey
  • 1
  • 11
  • 20
  • 40

1 Answers1

-1

Inside you're if(isset($_POST['country']))

After you're include() do:

$checkedSkills = implode(", ", $_POST['skills']);

...

$statement->execute(
    array(
        ':country'      =>  $_POST['country'],
        ':state'        =>  $_POST['state'],
        ':city'         =>  $_POST['hidden_city'],
        ':skills'           =>  $checkedSkills,
    )
);
Brian
  • 8,418
  • 2
  • 25
  • 32