0

I want to have a input that can change the value of a row in my database. (mysqli) For example:

if option 1 is selected, the row will change in the value of option 1. And if option 2 is selected, the row will change in the value of option 2. How do i do that? My code of the inc. file:

if(isset($_POST['adjust-groep'])) {
    $sqlGroep = 'UPDATE employee set groep=? WHERE ID=?';
    $stmtGroep = mysqli_stmt_init($conn);
    if(!mysqli_stmt_prepare($stmtGroep, $sqlGroep)) {
        echo 'MYSQLI statement mislukt';
    } else {
        mysqli_stmt_bind_param($stmtGroep, "si", $newGroep, $id);
        mysqli_stmt_execute($stmtGroep);
        $resultGroep = mysqli_stmt_get_result($stmtGroep);
        if(!$resultGroep) {
                header('Location: ../control.php?error=success');
                exit();            
        } else {
                header('Location: ../control.php?error=fail');
                exit();                
        }
    }
}

The other code of the select:

<form action="includes/controladjust.inc.php" class="form-group>
    <select name="adjust-Groep" class="custom-select" id="inputGroupSelect01">
        <option selected>Huidige groep: <?php echo $Groep  ?></option>
        <option name="Admin" value="2">Admin</option>                                
        <option name="user" value="3">user</option>                                
    </select>
    <button type="submit" name="adjust-groep" class="mt-2 btn btn-success">groep wijzigen</button>   
</form>

With kind regards,

2
  • mysqli_stmt_get_result() There is no result set from an UPDATE. Just a TRU or FALSE to tell you it worked or failed. Commented Feb 28, 2019 at 19:55
  • So $resultGroep = mysqli_stmt_execute($stmtGroep); will give you a boolean to test Commented Feb 28, 2019 at 19:56

1 Answer 1

1

You are using select wrongly

<option value="admin">Admin</option>

You don't have to use name attribute on it, just set value and in php, if admin is selected $_POST['adjust-groep'] will output admin, final code will be

mysqli_stmt_bind_param($stmtGroep, "si", $_POST['adjust-groep'], $id);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.