Post form not posting for some reason

So I recently started a project and am using a little bit of a different method than I would usually do to post forms and I have no clue why it will not post. I have 2 other post forms that are setup identically to this one and they work fine

Here is the actual form, the include just leads to the database information and a seperate form that includes all of the materials that I am using to call posts.

<?php include('check.php') ?>
<title>Create New License</title>

<link rel="stylesheet" type="text/css" href="../include/css/style.css">
<div class="header">

    <h2>Admin - create License</h2>

</div>



<form method="post" action="create_license.php">

<div class="input-group">

    <label>License Key</label>

    <input type="key" name="key">

</div>

    <div class="input-group">

        <label>Type of Key</label>

        <select type="type" name="type" id="user_type">

            <option value="1">7 days</option>

            <option value="2">30 days</option>

            <option value="3">Lifetime</option>

        </select>

    </div>

    </div>

      <input type="hidden" name="addlicense"value="test"> 

    </div>

    <div class="input-group">

        <button type="submit" class="btn" name="license_create_btn"> + Create license</button>

    </div>

</form>

// call the licensecreate() function if license_create_btnis clicked

if (isset($_POST[‘license_create_btn’])) {

licensecreate();

}

// CREATE LICENSE

function licensecreate(){

// call these variables with the global keyword to make them available in function

global $db, $errors;

// receive all input values from the form. Call the e() function

// defined below to escape form values

$key    =  e($_POST['key']);

$type  =  e($_POST['type']);

// form validation: ensure that the form is correctly filled

if (empty($key)) { 

    array_push($errors, "License Key is required"); 

}

if (count($errors) == 0) {

    if (isset($_POST['type'])) {

        $query = "INSERT INTO license (key, type) 

                  VALUES('$key', '$type')";

        mysqli_query($db, $query);

        $_SESSION['success']  = "New License successfully created!!";

        header('location: home.php');

    }else{

        header('location: index.php');              

    }

}

}

I’m not sure if this could just be a database issue or php as I am not getting any errors output in either mysql or php

You ALWAYS need error handling for database statements that can fail - connection, query, prepare, and execute. The easiest way of adding error handling for these statements, without adding conditional logic around each statement, is to use exceptions for database errors and in most cases let php catch and handle the exception, where php will use its error related settings to control what happens with the actual error information (database errors will automatically get displayed/logged the same as php errors.) The exception to this rule is when inserting/updating user submitted data and you need to detect duplicate values. In this case, your code should catch the exception, test if the sql error number is for a duplicate key value, then setup and display a message for the user telling them what was wrong with the data that they submitted. For all other error numbers, just re-throw the exception and let php handle it.

For the mysqli extension, to enable exceptions for errors, add the following line of code before the point where you make the database connection, then remove any existing error handling logic for the database statements as it will no longer get executed upon an error -

mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);

Once you do the above, you will be getting a mysqli error pointing to the problem with the sql query.

Sponsor our Newsletter | Privacy Policy | Terms of Service