lundi 4 mai 2015

Checkboxes - print checked values in checkbox from database

In insert form I am using check boxes to insert values in database. Now, I want to get checked values in edit form so I can check new values or uncheck checked values.
First I get values from database (I am using pdo, I will not post connection code to db- it works):

get oprmea from database
$sql_oprema = "SELECT Oprema FROM dbo_emarketing_stavke_oprema WHERE Partner='$id'";
  $n = $conn->query($sql_oprema);

  while ($r = $n -> fetch()) {
    $oprema_sql = $r['Oprema']; 
  }

I get values when I dump variables, output is not NULL. I am using function to store values in database. Now I want to use same function for editing if posssible.

function emarketing_oprema(){
    $link = new mysqli("localhost", "root", "le30mu09", "websoft");
    $link->set_charset("utf8");
    $sql=mysqli_query($link, "SELECT * FROM `dbo_emarketing_oprema` order by OpremaId asc ");

    while($record = mysqli_fetch_array($sql)) {
        echo '<input type="checkbox" name="oprema[]" value="'.$record['OpremaId']. '">' . $record['OpremaNaziv'] . ' <br/><br/> </input>';
    }
}

I was wondering is it possible to use this function to get checked values checked.




Aucun commentaire:

Enregistrer un commentaire