Need help please. ASAP

my code is below, i am getting an error message “Something Went Wrong. Please try again”

can somebody tell me what i have done wrong please

<?php
session_start();
error_reporting(1);
include('include/dbconnection.php');
if (strlen($_SESSION['pdaid']==0)) {
  header('location:logout.php');
  } else{

if(isset($_POST['submit']))
  {
    $fullname=$_POST['fullname'];
    $profession=$_POST['profession'];
    $email=$_POST['email'];
    $mobilenumber=$_POST['mobilenumber'];
    $address=$_POST['address'];
    $account_n=$_POST['account_n'];
    $sort=$_POST['sort'];
    $rent=$_POST['rent'];
    $bonus=$_POST['bonus'];
    $notes=$_POST['notes'];
    $city=$_POST['city'];
    $admsta=1;
     
    $query=mysqli_query($con, "insert into  tbldirectory(FullName,Profession,Email,MobileNumber,Address,account_n,sort,rent,bonus,notes,City,Status) value('$fullname','$profession','$email','$mobilenumber','$address','$account_n','$sort','$rent','$bonus','$notes','$city','$admsta')");
    if ($query) {
    $msg="Thank You. Client Details Have Been Added..";
  }
  else
    {
      $msg="Something Went Wrong. Please try again";
    }

  
}
  ?>



<!DOCTYPE html>
<html lang="en">

<head>

  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  <meta name="description" content="">
  <meta name="author" content="">

  <title>DMS</title>

  <!-- Custom fonts for this template-->
  <link href="vendor/fontawesome-free/css/all.min.css" rel="stylesheet" type="text/css">

  <!-- Page level plugin CSS-->
  <link href="vendor/datatables/dataTables.bootstrap4.css" rel="stylesheet">

  <!-- Custom styles for this template-->
  <link href="css/sb-admin.css" rel="stylesheet">

</head>

<body id="page-top">



    <!-- Navbar -->
    
<?php include('include/header.php');?>
  <div id="wrapper">

    <!-- Sidebar -->
    <?php include('include/sidebar.php');?>

    <div id="content-wrapper">

      <div class="container-fluid">

        <!-- Breadcrumbs-->
        <ol class="breadcrumb">
          
            
          </li>
          <li class="breadcrumb-item active">Personal Details</li>
        </ol>
 <p style="font-size:16px; color:red" align="center"> <?php if($msg){
    echo $msg;
  }  ?> </p>
        <!-- Icon Cards-->
        
        <!-- Area Chart Example-->
        

        <!-- DataTables Example -->
        <form name="directory" method="post">
          <div class="form-group">
            <div class="form-row">
              <div class="col-md-6">
                <div class="form-label-group">
                  <input type="text" id="fullname" name="fullname" class="form-control"  required="required" autofocus="autofocus">
                  <label for="firstName">First Name</label>
                </div>
              </div>
              <div class="col-md-6">
                <div class="form-label-group">
                  <input type="text" id="profession" name="profession" class="form-control"  required="required">
                  <label for="lastName">Surname</label>
                </div>
              </div>
            </div>
          </div>
          <div class="form-group">
            <div class="form-label-group">
              <input type="email" id="email" name="email" class="form-control"  required="required">
              <label for="inputEmail">Email address</label>
            </div>
          </div>
          <div class="form-group">
            <div class="form-row">
              <div class="col-md-6">
                <div class="form-label-group">
                  <input type="text" id="mobilenumber" name="mobilenumber" maxlength="11" class="form-control"  required="required">
                  <label for="firstName">Mobile Number</label>
                </div>
              </div>
              <div class="col-md-6">
                <div class="form-label-group">
                  <input type="text" id="city" name="city" class="form-control"  required="required" autofocus="autofocus">
                  <label for="firstName">City</label>
                </div>
              </div>
              
            </div>
          </div>
          <div class="form-group">
            <div class="form-label-group">
              <input type="text" id="address" name="address" class="form-control"  required="required">
              <label for="firstName">Address</label>
            </div>
          </div>
          
          

        <!-- Breadcrumbs-->
        <ol class="breadcrumb">
          
            <li class="breadcrumb-item active">Bank Account Details</li>
         
         
          
        </ol>
     
         
        <div class="form-group">
            <div class="form-label-group">
              <input type="text" id="account_n" name="account_n" class="form-control"  required="required">
              <label for="inputEmail">Account Number</label>
            </div>
          </div>
          
         <div class="form-group">
            <div class="form-label-group">
              <input type="text" id="sort" name="sort" class="form-control" required="required">
              <label for="inputEmail">Sort Code</label>
            </div>
          </div>
           
           
            <!-- Breadcrumbs-->
        <ol class="breadcrumb">
          
            <li class="breadcrumb-item active">Property Details</li>
         
         
          
        </ol>
        
        
        
        
        
        
        
        
        
        
        
        
        <div class="form-group">
            <div class="form-row">
              <div class="col-md-6">
                <div class="form-label-group">
                  <input type="text" id="rent" name="rent" class="form-control"  required="required" autofocus="autofocus">
                  <label for="firstName">Required Rent PCM (£)</label>
                </div>
              </div>
              <div class="col-md-6">
                <div class="form-label-group">
                  <input type="text" id="bonus" name="bonus" class="form-control"  required="required">
                  <label for="lastName">Agreed Bonus or Extra (£)</label>
                </div>
              </div>
            </div>
          </div>
           
           
           
           
           
           
           
            <!-- Breadcrumbs-->
        <ol class="breadcrumb">
          
            <li class="breadcrumb-item active">Notes/Comments</li>
         
         
          
        </ol>
           
           
           
           <div class="col-md-6">
                <div class="form-label-group">
                  <input type="text" id="notes" name="notes" class="form-control" style="height: 250px;" required="required">
                  <label for="lastName">Client Notes</label>
                </div>
              </div>
            
            
           
           
           
           
           <br>
          
        <center><button type="submit" name="submit" class="btn btn-info btn-min-width mr-1 mb-1">ADD NEW CLIENT</button></p>
        </form>

      </div>
      <!-- /.container-fluid -->

      <!-- Sticky Footer -->
      <?php include('include/footer.php');?>

    </div>
    <!-- /.content-wrapper -->

  </div>
  <!-- /#wrapper -->

  <!-- Scroll to Top Button-->
  <a class="scroll-to-top rounded" href="#page-top">
    <i class="fas fa-angle-up"></i>
  </a>

  <!-- Logout Modal-->
  <div class="modal fade" id="logoutModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
    <div class="modal-dialog" role="document">
      <div class="modal-content">
        <div class="modal-header">
          <h5 class="modal-title" id="exampleModalLabel">Ready to Leave?</h5>
          <button class="close" type="button" data-dismiss="modal" aria-label="Close">
            <span aria-hidden="true">×</span>
          </button>
        </div>
        <div class="modal-body">Select "Logout" below if you are ready to end your current session.</div>
        <div class="modal-footer">
          <button class="btn btn-secondary" type="button" data-dismiss="modal">Cancel</button>
          <a class="btn btn-primary" href="logout.php">Logout</a>
        </div>
      </div>
    </div>
  </div>

  <!-- Bootstrap core JavaScript-->
  <script src="vendor/jquery/jquery.min.js"></script>
  <script src="vendor/bootstrap/js/bootstrap.bundle.min.js"></script>

  <!-- Core plugin JavaScript-->
  <script src="vendor/jquery-easing/jquery.easing.min.js"></script>

  <!-- Page level plugin JavaScript-->
  <script src="vendor/chart.js/Chart.min.js"></script>
  <script src="vendor/datatables/jquery.dataTables.js"></script>
  <script src="vendor/datatables/dataTables.bootstrap4.js"></script>

  <!-- Custom scripts for all pages-->
  <script src="js/sb-admin.min.js"></script>

  <!-- Demo scripts for this page-->
  <script src="js/demo/datatables-demo.js"></script>
  <script src="js/demo/chart-area-demo.js"></script>


</body>

</html>
<?php }  ?>

Why do you have some many div elements in a form? A form can easily be stylized with CSS and with would be easier to find out where you problem is. I am assuming you have error reporting turned on as it looks like you are getting a logic error? Make sure all your variables match you database table column names.

Here’s an example of how I add trivia questions to my trivia game.

<?php

require_once '../private/initialize.php';

use Library\Trivia\Trivia;

$create = new Trivia();
$data = [];

$submit = filter_input(INPUT_POST, 'submit', FILTER_SANITIZE_FULL_SPECIAL_CHARS);
if (isset($submit) && $submit === 'submit') {
    $data['question'] = filter_input(INPUT_POST, 'question', FILTER_DEFAULT);
    $data['answer1'] = filter_input(INPUT_POST, 'answer1', FILTER_SANITIZE_SPECIAL_CHARS);
    $data['answer2'] = filter_input(INPUT_POST, 'answer2', FILTER_SANITIZE_SPECIAL_CHARS);
    $data['answer3'] = filter_input(INPUT_POST, 'answer3', FILTER_SANITIZE_SPECIAL_CHARS);
    $data['answer4'] = filter_input(INPUT_POST, 'answer4', FILTER_SANITIZE_SPECIAL_CHARS);
    $data['correct'] = filter_input(INPUT_POST, 'correct', FILTER_SANITIZE_SPECIAL_CHARS);
    $data['category'] = filter_input(INPUT_POST, 'category', FILTER_SANITIZE_SPECIAL_CHARS);
    $result = $create->create($data);
    if ($result) {
        header("Location: trivMain.php");
        exit;
    }
}
confirm_user_logged_in();
is_session_valid();
include '../private/includes/header.inc.php';
?>
<section class="main">
    <form id="addTriviaQA" action="trivMain.php" method="post">
        <fieldset>
            <legend id="legend">Add Trivia Question(s)</legend>
            <input id="id" type="hidden" name="id" value="0">
            <input type="hidden" name="user_id" value="">
            <select class="select-css" name="category" tabindex="1">
                <option value="photography">Photography</option>
                <option value="movie">Movie</option>
                <option value="space">Space</option>
            </select>
            <textarea id="addQuestion" name="question" tabindex="2" placeholder="Add question here..." autofocus></textarea>
            <label for="addAnswer1">Answer 1</label>
            <input id="addAnswer1" type="text" name="answer1" value="" tabindex="3">
            <label for="addAnswer2">Answer 2</label>
            <input id="addAnswer2" type="text" name="answer2" value="" tabindex="4">
            <label for="addAnswer3">Answer 3</label>
            <input id="addAnswer3" type="text" name="answer3" value="" tabindex="5">
            <label for="addAnswer4">Answer 4</label>
            <input id="addAnswer4" type="text" name="answer4" value="" tabindex="6">   
            <label for="addCorrect">Answer</label>
            <input id="addCorrect" type="text" name="correct" value="" tabindex="7">
            <input id="submitBtn" type="submit" name="submit" value="submit" tabindex="8">
        </fieldset>


    </form>    
</section>
<?php

include '../private/includes/footer.inc.php';

Here’s my database table structure:

-- phpMyAdmin SQL Dump
-- version 4.8.5
-- https://www.phpmyadmin.net/
--
-- Host: localhost:3306
-- Generation Time: Feb 24, 2020 at 04:15 PM
-- Server version: 5.7.25
-- PHP Version: 7.2.14

SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
SET time_zone = "+00:00";

--
-- Database: `cms`
--

-- --------------------------------------------------------

--
-- Table structure for table `trivia_questions`
--

CREATE TABLE `trivia_questions` (
  `id` int(11) NOT NULL,
  `user_id` int(11) NOT NULL DEFAULT '1',
  `hidden` varchar(15) COLLATE latin1_german2_ci NOT NULL DEFAULT 'no',
  `question` text COLLATE latin1_german2_ci NOT NULL,
  `answer1` char(100) COLLATE latin1_german2_ci NOT NULL,
  `answer2` char(100) COLLATE latin1_german2_ci NOT NULL,
  `answer3` char(100) COLLATE latin1_german2_ci NOT NULL,
  `answer4` char(100) COLLATE latin1_german2_ci NOT NULL,
  `correct` int(1) NOT NULL,
  `category` varchar(60) COLLATE latin1_german2_ci NOT NULL,
  `play_date` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_german2_ci;

Notice my PHP variables match my structure column names to database table column names. I recommend using PDO over mysqli as it is more versatile and really not that difficult to learn.

Here’s a good website explaining PDO - https://phpdelusions.net/pdo and another good link is https://www.bitdegree.org/learn/php-pdo

Though if you insist on using mysqli I think you have to match the ? marks with the amount of column fields/names you have, but it’s been a long time since I used mysql that I might be wrong.

thank you for your response but i really don’t know what you mean, can i put a link on here to my website so you can maybe check it out PLEASE?

It looks like the problem is with your database; either with the connection or the structure of the query. Add the following to your last else block:

else {
    $msg = "Something Went Wrong. Please try again";
    echo mysqli_error($con);
}

That should print the database error and we can see what’s going on exactly.

Sponsor our Newsletter | Privacy Policy | Terms of Service