html - How do I call an array inside a session array in this 3 part PHP registration form




The values of your checkboxes are stored in an array in $_POST, and you'll need to loop over them to get a value for each:

// Initialise interest list as empty string
$interestList = '';

// Loop through checked interests
foreach($_POST['interests'] as $interest){
    // Add checked interest to string containing list of interests
    $interestList .= $interest . ', ';

// Remove last comma and space from interest list
if(strlen($interestList)) {
    $interestList = substr($interestList, 0, -2);

In order to pop up a warning regarding refreshing the page, you'll want to usewindow.onbeforeunload somewhere in your javascript. Browser compatibility for this is patchy, and might not give you the result you want.

Stack Overflow answer for pop-up on refresh

MDN web docs for window.onbeforeunload (compatibility)

Regarding coding style:

Coding style is a matter of opinion, so we can't really give you an answer on Stack Overflow. Your code's readable and understandable which is a really good start. I think, generally, the consensus is use a lot of comments and more controversially use some frameworks.

Just keep in mind that the secondary goal in programming, aside from making a thing that works, is producing code which other programmers can read, and code which will make sense to you when you come back to it in 6 months time after having completely forgotten about it.

People are also looking for solutions to the problem: Protection against unauthorized redeployment of PHP applications


Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.