Skip to content
Advertisement

Form is not submitting to database [closed]

So after I enter the information on my form it refreshes the new.php page with a new form but doesn’t submit any information. I get no errors its just like I clicked refresh on the page. I feel like i’ve done everything right but I just can’t seem to figure out why this isn’t working. I’ve just transitioned from mysql to mysqli so I’m kinda a noob with it. It’s also not routing back to home.php.

new.php

<?php include_once('header.php'); ?>
<?php include_once('config/db.php'); ?>




<div id="newform">
    <form role="form">
        <div class="form-group">
            <label for="user">User</label>
            <input type="text" class="form-control" id="user" placeholder="Username"> 
        </div>
        <div class="form-group">
            <label for="rank">Rank</label>
            <select class="form-control" name="rank">
                <option value="1">Noob</option>
                <option value="2">Semi-Noob</option>
            </select>
        </div>
        <div class="form-group">
            <label for="date">Date</label>
            <input type="text" class="form-control" id="date" placeholder="<?php echo date('d M y'); ?>">
        </div>
        <div class="form-group">
            <label for="tag">Tag</label>
            <input type="text" class="form-control" id="tag" placeholder="Tag">
        </div>      
        <center>
        <button type="submit" class="btn btn-default">Submit</button>
        </center>
    </form>
</div>

<?php
if(isset($_POST['submit'])){
//Values to be inserted into the DB
$user = $_POST['user'];
$rank = $_POST['rank'];
$date = $_POST['date'];
$tag  = $_POST['tag'];

//Preparing the statement
$query = "INSERT INTO players (user, rank, date, tag) VALUES(?, ?, ?)";
$statement = $mysqli->prepare($query);

//Binding Parameters for markers, where (s = string, i = integer, d = double, b = blob)
$statement->bind_param('siss', $user, $rank, $date, $tag);

//Execution
if($statement->execute()){
    header('Location: home.php');
}else{
    die('Error : ('.$mysqli->errno .') '. $mysqli->error);
}
$statement->close();
}
?>

<?php include_once('footer.php'); ?>

Advertisement

Answer

Check after adding name="submit" in <button type="submit" class="btn btn-default">Submit</button>

<button type="submit" class="btn btn-default" name="submit">Submit</button>
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement