PHP Checkbox can not show checked on edit page -


there problem show checked in checkbox on edit page. there code below:

ssc<input type="checkbox"  name="ssc"class="form-control" value="ssc"  <?php if(isset($ssc)) echo ($data[6] == 'ssc') ? 'checked':''; ?>/>  hsc<input type="checkbox"  name="hsc" class="form-control" value="hsc"  <?php if(isset($hsc)) echo ($data[6] == 'hsc') ? 'checked':''; ?>/> 

okay, lets go throw issues

  • mysql functions deprecated
  • currently possible attacker can inject malicious sql because way pass variables
  • beacuse $data variable contains education column
  • the value of checkbox sent if checked otherwise it's not set
  • the educatio column can contain 3 value , none of them equals data
    • ssc
    • ssc hsc
    • hsc

solutions:

  • use mysqli functions instead mysql
  • use prepared statements , parameterized queries.
  • don't check if column set if defined select query
  • always check if checkbox value sent isset or add hidden input same name , empty value above checkbox if box not checked value of hidden input sent
  • check if string contains "words" (strpos($a, 'ssc') !== false - it's true when not false)

(and not use answer section give aditional data update question instead)


Comments