Skip to content Skip to sidebar Skip to footer

Not Updating Sql Database

For some reason my code isn't updating mySQL database, but it isn't reporting any errors. register.php (form)

Solution 1:

Here's a working sample with prepared statements, that are "better" to use generally instead of query

action.php

$con = new mysqli('localhost', 'root', '', 'dachi');

if (mysqli_connect_errno()) {
    printf("Connect failed: %s\n", mysqli_connect_error());
    exit();
}

if (isset($_GET['do']) && $_GET['do'] === "register") {
    $teamname = $_POST["teamname"];
    $teamregion = $_POST["teamregion"];
    $teamleader = $_POST["teamleader"];
    $teammembers = $_POST["teammembers"];
    $wins = 0;
    $loses = 0;

    $stmt = $con->prepare("INSERT INTO `teams` (`teamname`,`region`,`teamleader`,`teammembers`,`wins`,`loses`) VALUES (?,?,?,?,?,?)");
    $stmt->bind_param('ssssii', $teamname, $teamregion, $teamleader, $teammembers, $wins, $loses);
    $stmt->execute();
    $stmt->close();
}

register.php

<form class="register_form" action="action.php?do=register" method="post">
    Team Name*: <inputtype="text" name="teamname" required />
    Team Region*: <inputtype="text" name="teamregion" maxlength="4" required />
    Team Leader*: <inputtype="text" name="teamleader" maxlength="16" required />
    Team Members: <inputtype="text" name="teammembers"  />
    <input name="register_submit"type="submit" value="Register" />
</form>

Solution 2:

You should change:

if($action=="register") {

to

if($action=="register_submit") {

Because your input has a tag name set to value register_submit not register.

and change $action = $_GET['do']; to $action = $_POST['register_submit'];

Solution 3:

register.php (form)

<form class="register_form" action="action.php?do=register" method="post">

action.php

$action = $_GET['do'];

Post a Comment for "Not Updating Sql Database"