select to foreign key column:无法添加或更新子行:外键约束失败

I am trying to pass values from a select field populated from the database to a table which has a foreign key column

The form

 <?php
       require ('aaa2/conn/auth.php');

       $select = "SELECT * FROM aaa_categories";
       $res = mysqli_query($conn, $select) or die(mysqli_error($conn));

       if (mysqli_num_rows($res)) {
              echo "<select name='aaa_cat' class='form-control' id='aaa-cat' required>";
              echo "<option selected>--Select a category that best fits your petition--</option>";
              while ($row = mysqli_fetch_array($res)) {
                    echo '<option value="'.$row['aaa_categories_id'].'">'.$row['aaa_categories_name'].'</option>';
                                    }
                    echo "</select>";
                                }
 ?>

The Processor

$aaa_details = mysqli_real_escape_string($conn, $_POST['aaa_details']);
$aaa_cat = mysqli_real_escape_string($conn, $_POST['aaa_cat']);
$query = "INSERT INTO aaa (aaa_detail, aaa_cat)VALUES ('$aaa_details', '$aaa_cat')";
$result = mysqli_query($conn, $query) or die(mysqli_error($conn));

The Schema

    CREATE TABLE IF NOT EXISTS `aaa_db`.`aaa` (
  `aaaid` INT NOT NULL AUTO_INCREMENT,
  `userid` INT NOT NULL,
  `aaa_categories_id` INT NOT NULL,
  `aaa_detail` VARCHAR(350) NULL,
  PRIMARY KEY (`aaaid`),
  INDEX `fk_aaa_users1_idx` (`userid` ASC),
  INDEX `fk_aaa_aaa_categories1_idx` (`aaa_categories_id` ASC),
  CONSTRAINT `fk_aaa_users1`
    FOREIGN KEY (`userid`)
    REFERENCES `aaa_db`.`users` (`userid`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
  CONSTRAINT `fk_aaa_aaa_categories1`
    FOREIGN KEY (`aaa_categories_id`)
    REFERENCES `aaa_db`.`aaa_categories` (`aaa_categories_id`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = InnoDB;

The Error

Cannot add or update a child row: a foreign key constraint fails (`aaa_db`.`aaa`, CONSTRAINT `fk_aaa_aaa_categories1` FOREIGN KEY (`aaa_categories_id`) REFERENCES `aaa_categories` (`aaa_categories_id`) ON DELETE NO ACTION )

I have been struggling with this for 3 days now, I appreciate any advice. Thanks

Your query

INSERT INTO aaa (aaa_detail, aaa_cat)VALUES ('$aaa_details', '$aaa_cat')

doesn't seem to correspond to your actual schema unless aaa_cat == aaa_categories_id

If that is the case the error you get is strange. I would understand it if it was complaining about forconstraint "fk_aaa_users1", as you are not inserting anything in the relevant column.

Please review the information you posted and advise. I will then update this answer accordingly ...