UPDATE table MySQL

  html, mysql, php

I have a MySQL table called "partners".
MySQL table

I want to UPDATE the values in the table WHERE partner = $_SESSION[‘username’]; via an HTML form.
I think the error is as follows:

MySQL database table has several columns, but I want to change only some of them, if I don’t specify them all it doesn’t work, can it be?
So, this is the code:

<?php
setlocale(LC_ALL, 'it_IT');
session_start();

$servername='localhost';
$username='username';
$password='password';
$dbname = "dbname";
$conn=mysqli_connect($servername,$username,$password,"$dbname");
if(!$conn){
   die('Impossibile stabilire la connessione al database:' .mysql_error());
}

if(isset($_POST['submit']))
{    
     $partner = $_SESSION['username'];
     $recapito_telefonico = $_POST['recapito_telefonico'];
     $indirizzo_email = $_POST['indirizzo_email'];
     $iban = $_POST['iban'];
     $istituto_bancario = $_POST['istituto_bancario'];
   
     $sql = "UPDATE partners SET partner = '$partner', iban = '$iban', istituto_bancario = '$istituto_bancario', recapito_telefonico = '$recapito_telefonico', indirizzo_email = '$indirizzo_email') WHERE partner='$partner'";
     if (mysqli_query($conn, $sql)) {
        header('location: url?status=success');
     exit();
     } else {
        echo "Errore: " . $sql . "
" . mysqli_error($conn);
     }
     mysqli_close($conn);
}
?>
<form action="../includes/core/modifca-profilo.php" method="post">
    <div class="form-group">
        <label for="label-telefono" class="form-control-label">Recapito telefonico*</label>
        <input class="form-control" type="tel" id="label-telefono" required="" name="recapito_telefonico">
    
        <label for="label-email" class="form-control-label">Indirizzo e-mail di contatto*</label>
        <input class="form-control" type="email" id="label-email" required="" name="indirizzo_email">
    
        <label for="label-iban" class="form-control-label">IBAN*</label>
        <input class="form-control" type="text" id="label-iban" required="" name="iban">
    
        <label for="label-istitutobancario" class="form-control-label">Istituto bancario*</label>
        <input class="form-control" type="text" id="label-istitutobancario" required="" name="istituto_bancario">
    
        <div style="margin-top: 10px;">
            <small>I campi contrassegnati con (*) sono obbligatori.</small>
        </div>
    
        <div class="form-check" style="margin-top: 20px;">
            <input class="form-check-input" type="checkbox" value="SI" id="check-privacy" checked="" required="" name="privacy">
            <label class="custom-control-label" for="check-privacy">Sono consapevole che la modifica di questi dati &egrave; sensibile, pertanto mi impegno a segnalarla all'ufficio di zona competente.*</label>
        </div>
    
        <div class="form-check" style="margin-top: 10px;">
            <input class="form-check-input" type="checkbox" value="SI" id="check-ricontatto" checked="" required="" name="ricontatto">
            <label class="custom-control-label" for="check-ricontatto">Accetto e sottoscrivo l'informativa sulla Privacy e ToS.</label>
        </div>
    
        <input style="margin-top: 30px; color: white; background-color: #0052CC;" class="form-control" value="Modifica" type="submit" name="submit">
    </div>
</form> 

Where did I fail?

Source: Ask PHP

LEAVE A COMMENT