at last i got the checkboxes to work and add to database but the only this i need advice on if i refresh the page the selected items disappear how can i solve this the

php file is as follows

<?php
include("config/db_connect.php");

extract($_POST);
$check_exist_qry="select * from interests";
$run_qry=mysqli_query($conn,$check_exist_qry);
$total_found=mysqli_num_rows($run_qry);
if($total_found >0)
{
    $my_value=mysqli_fetch_assoc($run_qry);
    $my_stored_interests=explode(',',$my_value['interest_name']);
}

if(isset($submit))
{
    $all_interests_value = implode(",",$_POST['interests']);
    if($total_found >0)
    {
        //update
        $upd_qry="UPDATE interests SET interest_name='".$all_interests_value."'";
        mysqli_query($conn,$upd_qry);

    }
    else
    {
        //insert
        $ins_qry="INSERT INTO interests(interest_name) VALUES('".$all_interests_value."')";
        mysqli_query($conn,$ins_qry);
    }
}
if (!empty($_POST['submit'])) {
echo "<ul>";
foreach ($_POST['interests'] as $value) {
echo "<li>$value</li>";
}
echo "</ul>";
} else {
echo "none";
}
?> 

what selected items? i dont understand the question. If you need to save info across refreshing you can use $_SESSION

Member Avatar for diafol

As TobyITguy says use session to propagate between pages. However, I see that you are using a vanilla extract() for $_POST data. I believe the danger of this was pointed out to you in a previous thread, but you have not addressed it. And you're still referencing $_POST vars after the extract() method. So what's the point? The extract() method could be a problem as it overwrites variables witht he same name by default. Have a look at the various flags that you could use to prevent a malicious user from posting dodgy POST 'keys'. Flags like EXTR_PREFIX_ALL may be useful.

ive noticed the post and removed extract() off and have been trying sessions most of day and i am still getting issues on after i submit the data i get
option1
option2
option3

echoed through but if i refresh i get

none echoed through

i have the sessions like below

$_SESSION["interests"]=$option1;
$_SESSION["interests"]=$option2;
$_SESSION["interests"]=$option3;
$_SESSION["interests"]=$option4;
$_SESSION["interests"]=$option5;
$_SESSION["interests"]=$option6;
$_SESSION["interests"]=$option7;

if(isset($_REQUEST['option1']) && $_REQUEST['option1']=="option1"){
       $option1 = $_POST['option1']; // check box value
       }
  if(isset($_REQUEST['option2']) && $_REQUEST['option2']=="option2"){
       $option2 = $_POST['option2']; // check box value
       }
       if(isset($_REQUEST['option3']) && $_REQUEST['option3']=="option3"){
       $option3 = $_POST['option3']; // check box value
       }
       if(isset($_REQUEST['option4']) && $_REQUEST['option4']=="option4"){
       $option4 = $_POST['option4']; // check box value
       }
       if(isset($_REQUEST['option5']) && $_REQUEST['option5']=="option5"){
       $option5 = $_POST['option5']; // check box value
       }
       if(isset($_REQUEST['option6']) && $_REQUEST['option6']=="option6"){
       $option6 = $_POST['option6']; // check box value
       }
       if(isset($_REQUEST['option7']) && $_REQUEST['option1']=="option7"){
       $option7 = $_POST['option7']; // check box value
       }

i dont know if im doing this bit right as im totally new to sessons and even after i did this nothing is saving i have also put session_start(); on both the file where the form is and also there file where the code is sat

i think i sussed it ill update tomorrow

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.