Click here to Skip to main content
15,886,919 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
In the table in the database contains the column date, checkbox. How can I disable the checkbox if the inputted date is already in the database.For example, if in the table contains date = 13/9/2019 and checkbox = h1, then if we input the date 13/9/2019, the checkbox h1 is disabled



HTML
<input type="checkbox" name="checkbox[]" id="checkbox" value="h1">
<input type="checkbox" name="checkbox[]" id="checkbox" value="h2">
<input type="date" name="date" id="date">

PHP
<?php 
$db = mysqli_connect('localhost','root','','mydatabase');
if (isset($_POST['date2'])){
$query = mysqli_query($db, "SELECT * FROM mytable where date ='".$_POST["date2"]."'");
// what to put here?
}
?>

JavaScript
$(document).ready(function {
  $("#date").change(function {
    var date = $("#date").val();

    $.ajax({
      url: "variable.php",
      method: "POST",
      data: {
        date2: date
      },
      dataType: "text",
      success: function(html) {
        //what to put here?
      }
    });
  });
});


What I have tried:

I have tried to echo checkbox val, but no luck
Posted
Updated 30-Sep-19 20:08pm
v2
Comments
Richard Deeming 27-Sep-19 9:03am    
Your code is vulnerable to SQL Injection[^]. NEVER use string concatenation to build a SQL query. ALWAYS use a parameterized query.

PHP: SQL Injection - Manual[^]

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900