0

Everything works expect the mysqli_query, the page dies error.

Does anyone have any idea why this could be?

$fileNameNew = uniqid('', true).".".$fileActualExt;
                $fileDestination = 'uploads/'.$fileNameNew;
                move_uploaded_file($fileTmpName, $fileDestination);

            
            $cid = $_GET['cid'];
            $scid = $_GET['scid'];
            
            $insert = mysqli_query($con, "INSERT INTO topics (`category_id`, `subcategory_id`, `author`, `title`, `content`, `date_posted`, `image`)
                                      VALUES ('".$cid."', '".$scid."', '".$_SESSION['username']."', '".$topic."', '".$content."', NOW()), '".$fileNameNew."';");
                                      
            if ($insert) {
                header("Location: /origo/topics.php?cid=".$cid."&scid=".$scid."");
            } else {
            die("error");
            }

Thank you

  • Do you have any `errors` ? did you check the `error_log` file for any possible error? – Burhan Kashour Nov 08 '20 at 15:48
  • 1
    You need to enable **error reporting** in order to learn why does your query fail. However, most likely the reason is the way you are adding variables to SQL. You should never add any variable directly but through a marker. See [how it must be done](https://stackoverflow.com/a/7537500/285587) – Your Common Sense Nov 08 '20 at 15:51
  • I get the error message "Cannot add or update a child row: a foreign key constraint fails (`mathiove_forum`.`topics`, CONSTRAINT `topics_ibfk_2` FOREIGN KEY (`subcategory_id`) REFERENCES `subcategories` (`subcat_id`))" – Jakob Åkesson Nov 08 '20 at 17:53

0 Answers0