html – Update Database with form on php

I need to make a form where I can update the data of the logged in user. The recorded data is in SQL. However, I’ve tried in several ways but I don’t know how to do it. I leave here the code for us to try together, make the form to update the data.

Database: https://i.stack.imgur.com/QZs68.png

updateprofile.php

<?php
session_start();
require('config.php');
if(!$con){
    header('location:erro.php');
}

$sql=sprintf("select * from utilizadores where email="".$_SESSION["email']."'");
$res=mysqli_query($con,$sql);
mysqli_set_charset($con, 'UTF8');

?>


<!DOCTYPE html>
<html>
<head>
    <!-- ==========================
        Meta Tags 
    =========================== -->
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    
    <!-- ==========================
        Title 
    =========================== -->
    <title>Buy tickets</title>
        
    <!-- ==========================
        Fonts 
    =========================== -->
    <link href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:400,200,200italic,300,300italic,400italic,600,600italic,700,700italic,900,900italic&amp;subset=latin,latin-ext" rel="stylesheet" type="text/css">
    <link href="https://fonts.googleapis.com/css?family=Raleway:400,100,200,300,500,600,700,900,800" rel="stylesheet" type="text/css">

    <!-- ==========================
        CSS 
    =========================== -->
    <link href="assets/css/bootstrap.min.css" rel="stylesheet" type="text/css">
    <link href="https://code.jquery.com/ui/1.11.1/themes/smoothness/jquery-ui.css" rel="stylesheet" type="text/css">
    <link href="assets/css/font-awesome.min.css" rel="stylesheet" type="text/css">
    <link href="assets/css/dragtable.css" rel="stylesheet" type="text/css">
    <link href="assets/css/owl.carousel.css" rel="stylesheet" type="text/css">
    <link href="assets/css/animate.css" rel="stylesheet" type="text/css">
    <link href="assets/css/color-switcher.css" rel="stylesheet" type="text/css">
    <link href="assets/css/custom.css" rel="stylesheet" type="text/css">
    <link href="assets/css/color/red.css" id="main-color" rel="stylesheet" type="text/css">
    
    <!-- ==========================
        JS 
    =========================== -->
    <!--[if lt IE 9]>
      <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
      <script src="https://oss.maxcdn.com/libs/respond.js/1.3.0/respond.min.js"></script>
    <![endif]-->
    
</head>
<body>
    
    <!-- ==========================
        SCROLL TOP - START 
    =========================== -->
    <div id="scrolltop" class="hidden-xs"><i class="fa fa-angle-up"></i></div>
    <!-- ==========================
        SCROLL TOP - END 
    =========================== -->
    
    <!-- ==========================
        COLOR SWITCHER - START 
    =========================== -->
    
    <!-- ==========================
        COLOR SWITCHER - END 
    =========================== -->
    
    <div id="page-wrapper"> <!-- PAGE - START -->
    
    <!-- ==========================
        HEADER - START 
    =========================== -->
    <div class="top-header hidden-xs">
        <div class="container">
            <div class="row">
                <div class="col-sm-5">
                    <ul class="list-inline contacts">
                        <li><i class="fa fa-envelope"></i> store@mail.com</li>
                        <li><i class="fa fa-phone"></i> 1820</li>
                    </ul>
                </div>
                <div class="col-sm-7 text-right">
                    <ul class="list-inline links">
                        <ul><a href="index.php">Página Inicial</a></ul>
                    </ul>
                </div>
            </div>
        </div>
    </div>
        
        
   <header class="navbar navbar-transparent navbar-fixed-top">
        <div class="container" style="width: 50%;">
            <div class="navbar-header">
                <a href="index.php" class="navbar-brand"> <img src="logotipo.png"> </a>
                <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse"> <i class="fa fa-bars"></i> </button>
            </div>
                
               <!-- <div class="teatroarte"><img src="opcoes/teatroarte.png"></div>
                    <div class="musicafestivais"><img src="opcoes/musicafestivais.png"></div>
                        <div class="familia"><img src="opcoes/familia.png"></div>
                            <div class="quatro"><img src="opcoes/desportoaventura.png"></div> -->
                
            <div class="navbar-collapse collapse">
                <ul class="nav navbar-nav navbar-right">
                    <li class="dropdown">
                    </li>
                    <li class="dropdown megamenu">
                        <a href="#" class="dropdown-toggle" data-toggle="dropdown" data-hover="dropdown" data-delay="300" data-close-others="true">AGENDA</a>
                        <ul class="dropdown-menu">
                            <li class="col-sm-4 col-md-3">
                                <ul class="list-unstyled">
                                    <li class="title">2021</li>
                                    <li><a href="products.html">NOVEMBRO</a></li>
                                    <li><a href="products.html">DEZEMBRO</a></li>
                                </ul>
                            </li>
                            <li class="col-sm-4 col-md-3">
                                <ul class="list-unstyled">
                                    <li class="title">2022</li>
                                    <li><a href="products.html">JANEIRO</a></li>
                                    <li><a href="products.html">FEVEREIRO</a></li>
                                    <li><a href="products.html">MARÇO</a></li>
                                    <li><a href="products.html">ABRIL</a></li>
                                    <li><a href="products.html">MAIO</a></li>
                                    <li><a href="products.html">JUNHO</a></li>
                                    <li><a href="products.html">JULHO</a></li>
                                    <li><a href="products.html">AGOSTO</a></li>
                                    <li><a href="products.html">SETEMBRO</a></li>
                                    <li><a href="products.html">OUTUBRO</a></li>
                                    <li><a href="products.html">NOVEMBRO</a></li>
                                    <li><a href="products.html">DEZEMBRO</a></li>
                                </ul>
                            </li>
                            <li class="col-sm-4 col-md-3">
                                <ul class="list-unstyled">
                                    <li class="title">2023</li>
                                    <li><a href="products.html">JANEIRO</a></li>
                                    <li><a href="products.html">FEVEREIRO</a></li>
                                    <li><a href="products.html">MARÇO</a></li>
                                    <li><a href="products.html">ABRIL</a></li>
                                    <li><a href="products.html">MAIO</a></li>
                                    <li><a href="products.html">JUNHO</a></li>
                                    <li><a href="products.html">JULHO</a></li>
                                    <li><a href="products.html">AGOSTO</a></li>
                                    <li><a href="products.html">SETEMBRO</a></li>
                                    <li><a href="products.html">OUTUBRO</a></li>
                                    <li><a href="products.html">NOVEMBRO</a></li>
                                    <li><a href="products.html">DEZEMBRO</a></li>
                                </ul>
                            </li>
                        </ul>
                    </li>
                    <li class="dropdown navbar-cart hidden-xs">
                        <a href="carrinho.php" class="dropdown-toggle" data-toggle="dropdown" data-hover="dropdown" data-delay="300" data-close-others="true"><i class="fa fa-shopping-cart"></i></a>
                        <ul class="dropdown-menu">
                            
                               <!--<li>
                                <div class="row">
                                    <div class="col-sm-3">
                                        <img src="assets/images/products/product-1.jpg" class="img-responsive" alt="">
                                    </div>
                                    <div class="col-sm-9">
                                        <h4><a href="single-product.html">Fusce Aliquam</a></h4>
                                        <p>1x - $20.00</p>
                                        <a href="#" class="remove"><i class="fa fa-times-circle"></i></a>
                                    </div>
                                </div>
                            </li>
                            <!-- CART ITEM - END -->
                            
                            <!-- CART ITEM - START -->
                            <!--<li>
                                <div class="row">
                                    <div class="col-sm-3">
                                        <img src="assets/images/products/product-2.jpg" class="img-responsive" alt="">
                                    </div>
                                    <div class="col-sm-9">
                                        <h4><a href="single-product.html">Fusce Aliquam</a></h4>
                                        <p>1x - $20.00</p>
                                        <a href="#" class="remove"><i class="fa fa-times-circle"></i></a>
                                    </div>
                                </div>
                            </li>
                            <!-- CART ITEM - END -->
                            
                            <!-- CART ITEM - START -->
                            <!--<li>
                                <div class="row">
                                    <div class="col-sm-3">
                                        <img src="assets/images/products/product-3.jpg" class="img-responsive" alt="">
                                    </div>
                                    <div class="col-sm-9">
                                        <h4><a href="single-product.html">Fusce Aliquam</a></h4>
                                        <p>1x - $20.00</p>
                                        <a href="#" class="remove"><i class="fa fa-times-circle"></i></a>
                                    </div>
                                </div>
                            </li> -->
                            <!-- CART ITEM - END -->
                            
                            <!-- CART ITEM - START -->
                            <li>
                                <div class="row">
                                    <div class="col-sm-6">
                                        <a href="carrinho.php" class="btn btn-primary btn-block">Ver carrinho</a>
                                    </div>
                                    <div class="col-sm-6">
                                        <a href="checkout.html" class="btn btn-primary btn-block">Finalizar</a>
                                    </div>
                                </div>
                            </li>
                            <!-- CART ITEM - END -->
                            
                        </ul>
                    </li>
                    <li class="dropdown navbar-search hidden-xs">
                        <a href="#" class="dropdown-toggle" data-toggle="dropdown"><i class="fa fa-search"></i></a>
                        <ul class="dropdown-menu">
                            <li>
                                <form>
                                    <div class="input-group input-group-lg">
                                        <input type="text" class="form-control" placeholder="Pesquisar...">
                                        <span class="input-group-btn">
                                            <button class="btn btn-primary" type="button">Pesquisar</button>
                                        </span>
                                    </div>
                                </form>
                            </li>
                        </ul>
                    </li>
                    <li class="dropdown">
                        <a href="signin.php" class="fa fa-user" data-toggle="dropdown" data-hover="dropdown" data-delay="300" data-close-others="true"></a>
                        <ul class="dropdown-menu">
                            <li><a href="signin.php">Iniciar Sessão</a></li>
                            <li><a href="signup.php">Criar Conta</a></li>
                        </ul>
                    </li>
                </ul>
            </div>
        </div>
            </header>
        
    <!-- ==========================
        HEADER - END 
    =========================== -->   
    
    <!-- ==========================
        BREADCRUMB - START 
    =========================== -->
    <section class="breadcrumb-wrapper">
        <div class="container">
            <div class="row">
                <div class="col-xs-6">
                    <h2>Minha Conta</h2>
                    <p>Os Meus Dados</p>
                </div>
                <div class="col-xs-6">
                    <ol class="breadcrumb">
                        <li><a href="index.html">Home</a></li>
                        <li><a href="my-account.html">Minha Conta</a></li>
                        <li class="active">Informações Pessoais</li>
                    </ol>
                </div>
            </div>
        </div>
    </section>
    <!-- ==========================
        BREADCRUMB - END 
    =========================== -->
    
    <!-- ==========================
        MY ACCOUNT - START 
    =========================== -->
    <section class="content account">
        <div class="container">
            <div class="row">
                <div class="col-sm-3">
                    <aside class="sidebar">
                        
                        <!-- WIDGET:CATEGORIES - START -->
                        <div class="widget widget-navigation">
                            <ul class="nav nav-pills nav-stacked">
                                <li><a href="detalhesconta.php">Painel de Controlo</a></li>
                                <li class="active"><a href="perfil.php">Os Meus Dados</a></li>
                                <li><a href="bemvindoadmin.php">Voltar à Página Inicial</a></li>
                                <li><a href="../logout.php">Terminar Sessão</a></li>
                            </ul>
                        </div>
                        <!-- WIDGET:CATEGORIES - END -->
                        
                    </aside>
                </div>
                <div class="col-sm-9">
                    <article class="account-content">
                        
                        <div class="account-profile-top">
                            <div><img src="assets/images/default-avatar.png" alt=""></div>
                            
                            <?php
                while($reg=mysqli_fetch_array($res)){
                    $sql_consulta=sprintf("select * from utilizadores where id=%s;",$reg['id']);
                    $res_consulta=mysqli_query($con,$sql_consulta);
                   
                    $reg_consulta=mysqli_fetch_array($res_consulta);
                    ?>
                
                        <div><h3><?php echo $reg['nome']; ?> <?php echo $reg['apelido']; ?> <small><?php echo $reg['email']; ?> </small></h3></div>
                            
                            <form method="post" class="form-horizontal">
                            <div class="form-group">
                                <label class="col-md-4 col-lg-3 control-label">Utilizador:</label>
                                <div class="col-md-8 col-lg-12">
                                <input type="text" class="form-control" name="username" placeholder="<?php echo $reg['username']; ?> ">
                                </div>
                            </div>
                                <br>
                            <div class="form-group">
                                <label class="col-md-4 col-lg-3 control-label">Nome:</label>
                                <div class="col-md-8 col-lg-12">
                                <input type="text" class="form-control" name="nome" placeholder="<?php echo $reg['nome']; ?> ">
                                </div>
                            </div>
                            <br>
                            <div class="form-group">
                                <label class="col-md-4 col-lg-3 control-label">Apelido:</label>
                                <div class="col-md-8 col-lg-12">
                                <input type="text" class="form-control" name="apelido" placeholder="<?php echo $reg['apelido']; ?> ">
                                </div>
                            </div>
                            <br>
                            <div class="form-group">
                                <label class="col-md-4 col-lg-3 control-label">Telemóvel:</label>
                                <div class="col-md-8 col-lg-12">
                                <input type="text" class="form-control" name="telemovel" placeholder="<?php echo $reg['telemovel']; ?> ">
                                </div>
                            </div>
                            <br>
                            <div class="form-group">
                                <label class="col-md-4 col-lg-3 control-label">Morada:</label>
                                <div class="col-md-8 col-lg-12">
                                <input type="text" class="form-control" name="morada" placeholder="<?php echo $reg['morada']; ?> ">
                                </div>
                            </div>
                            <br>
                            <div class="form-group">
                                <label class="col-md-4 col-lg-3 control-label">Email:</label>
                                <div class="col-md-8 col-lg-12">
                                <input type="text" class="form-control" name="email" placeholder="<?php echo $reg['email']; ?> ">
                                </div>
                            </div>
                            <br>
                            <div class="form-group">
                                <label class="col-md-4 col-lg-3 control-label"> Password:</label>
                                <div class="col-md-8 col-lg-12">
                                <input type="text" class="form-control" name="passe">
                                </div>
                            </div>
                            <br>
                                
                            <div class="form-group">
                                <div class="col-md-offset-4 col-md-8 col-lg-offset-3 col-lg-9">
                                    <button type="submit" name="botao" class="btn btn-primary">Atualizar</button>
                                </div>
                            </div>
                        </form>
                        
                    <?php
                }
                
                ?>
                        </div>
                        
                        
                        
                        
                    </article>
                </div>
            </div>
        </div>
    </section>
    <!-- ==========================
        MY ACCOUNT - END 
    =========================== -->
        
    <!-- ==========================
        NEWSLETTER - START 
    =========================== -->
    
    <!-- ==========================
        NEWSLETTER - END 
    =========================== -->
    
    <!-- ==========================
        FOOTER - START 
    =========================== -->
    <footer class="navbar navbar-default">
        <div class="container">
            <div class="row">
                <div class="col-sm-5 col-xs-5">
                    <div class="footer-widget footer-widget-contacts">
                        <h4 style="color:White">CONTACTOS</h4>
                        <ul class="list-unstyled">
                            <li style="color: white"><i class="fa fa-envelope"></i>store@mail.com</li>
                            <li style="color: white"><i class="fa fa-phone"></i>1820</li>
                        </ul>
                    </div>
                </div>
                <div class="col-sm-5 col-xs-5">
                    <div class="footer-widget footer-widget-contacts">
                        <h4 style="color:White">REDES SOCIAIS</h4>
                        <ul class="list-unstyled">
                            <li class="social">
                                <a href="#"><img src="assets/icons/icon_facebook_circle_gray.png" height="30" width="30"> </a>
                                <a href="#"><img src="assets/icons/icon_instagram_circle_gray.png" height="30" width="30"></a>
                                <a href="#"><img src="assets/icons/icon_twitter_circle_gray.png" height="30" width="30"></a>
                            </li>
                        </ul>
                    </div>
                </div>
                <div class="col-sm-2 col-xs-2">
                    <div class="footer-widget footer-widget-links">
                        <h4 style="color:White">INFORMAÇÕES</h4>
                        <ul class="list-unstyled">
                            <b><li><a href="about-shop.html">Sobre a Loja</a></li></b>
                            <b><li><a href="terms-conditions.html">Termos e Condições</a></li></b>
                            <b><li><a href="privacy-policy.html">Politica de Privacidade</a></li></b>
                            <b><li><a href="faq.html">Perguntas Frequentes</a></li></b>
                            <b><li><a href="my-account.html">Minha Conta</a></li></b>
                        </ul>
                    </div>
                </div>
                
                
            </div>
            <div class="footer-bottom">
                <div class="row">
                    <div class="col-sm-6">
                        <b><p style="color:white; font-size:16px">© STORE 2022 Todos os direitos reservados.
                            <br>
                            Create</p></b>
                    </div>
                    <div class="col-sm-6">
                        <ul class="list-inline payment-methods">
                            <li style="color: white"><i class="fa fa-cc-mastercard"></i></li>
                            <li style="color: white"><i class="fa fa-cc-paypal"></i></li>
                           <li style="color: white"><i class="fa fa-cc-visa"></i></li>
                        </ul>
                    </div>
                </div>
            </div>
        </div>
    </footer>
    <!-- ==========================
        FOOTER - END 
    =========================== -->
    
    <!-- ==========================
        MODAL ADVERTISING  - START 
    =========================== -->
    
    <!-- ==========================
        MODAL ADVERTISING - END 
    =========================== -->
    
    </div> <!-- PAGE - END -->
    
    <!-- ==========================
        JS 
    =========================== -->        
    <script src="https://code.jquery.com/jquery-latest.min.js"></script>
    <script src="https://code.jquery.com/ui/1.11.1/jquery-ui.js"></script>
    <script src="https://maps.googleapis.com/maps/api/js?v=3.exp&amp;sensor=true"></script>
    <script src="assets/js/bootstrap.min.js"></script>
    <script src="assets/js/bootstrap-hover-dropdown.min.js"></script>
    <script src="assets/js/SmoothScroll.js"></script>
    <script src="assets/js/jquery.dragtable.js"></script>
    <script src="assets/js/jquery.card.js"></script>
    <script src="assets/js/owl.carousel.min.js"></script>
    <script src="assets/js/twitterFetcher_min.js"></script>
    <script src="assets/js/jquery.mb.YTPlayer.min.js"></script>
    <script src="assets/js/color-switcher.js"></script>
    <script src="assets/js/custom.js"></script>
</body>
</html>

Leave a Comment