Results 1 to 3 of 3

Thread: Problem with fetching information from HTML form and saving in mySQL through PHP.

  1. #1
    teamup is offline Junior Member
    Join Date
    Oct 2020
    Posts
    1

    Default Problem with fetching information from HTML form and saving in mySQL through PHP.

    Hi guys! I really can't go through this issue that I'm having with my code. Basically , I've created a HTML form that sends informations to a PHP page through the action="post" method. Then, PHP is supposed to do some checks and add this datas to a new row in a database.

    But, after executing the PHP script, nothing is saved in my database table.

    Could somebody help me fixing this? THANKS!


    HTML FORM:

    HTML Code:
      <!-- Dati Personali -->
                        <div class="register-top1 py-lg-3">
                            <div class="title-sec-w3layouts_pvt text-center">
                                <h4 class="w3layouts_pvt-head"><a name="Pdata">Dati Personali</a></h4>
                            </div>
                            <form action="userinfopost.php" method="post" enctype="multipart/form-data" class="register-wthree pt-md-5 pb-md-0 py-4">
                                <div class="form-group">
                                    <div class="row">
                                        <div class="col-md-6">
                                            <label>
                                                Nome
                                            </label>
                                            <input class="form-control" type="text" placeholder="Carlo" name="nome"
                                                required="">
                                        </div>
                                        <div class="col-md-6 mt-md-0 mt-4">
                                            <label>
                                                Cognome
                                            </label>
                                            <input class="form-control" type="text" placeholder="Rossi" name="cognome" required="">
                                        </div>
                                    </div>
                                </div>
    							<div class="form-group">
                                    <div class="row">
                                        <div class="col-md-6">
                                            <label>
                                                Data di nascita
                                            </label>
                                            <input class="form-control" type="date"  name="compleanno"
                                                required="">
                                        </div>
                                        <div class="col-md-6 mt-md-0 mt-4">
                                            <label>
                                                Luogo di residenza
                                            </label>
                                            <input class="form-control" type="text" name="residenza" required="">
                                        </div>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <div class="row">
                                        <div class="col-md-6">
                                            <label>
                                                Mobile
                                            </label>
                                            <input class="form-control" type="text" placeholder="+39 3485214788" name="cell"
                                                required="">
                                        </div>
                                        <div class="col-md-6 mt-md-0 mt-4">
                                            <label>
                                                Email
                                            </label>
                                            <input class="form-control" type="email" placeholder="example@email.com" name="email"
                                                required="">
                                        </div>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <div class="row">
                                        <div class="col-md-6 mt-md-0 mt-4">
                                            <label>
                                                Immagine del profilo &nbsp &nbsp											
                                            </label>
                                        </div>
                                    </div>
    								     <div class="row">
    
    								 <div class="col-md-6 mt-md-0 mt-4">
    								   <input name="image" type="file" />
    
                                    </div>
                                      </div>
                                </div>
                                <div class="row mt-3">
                                    <div class="col-md-12">
                                        <button type="submit" class="btn btn-agile btn-block w-100 font-weight-bold text-uppercase bg-theme">Invia</button>
                                    </div>
                                </div>
                            </form>
                        </div>
    					<hr>
                        <!--  //Dati personali-->



    PHP:

    PHP Code:
    <?php

    session_start
    (); // inizializzo la sessione


    //collegamento DB
    $db=mysql_connect("localhost","teamup","");
    // Qui sotto al posto di NOME_DATABASE, inserite il nome del vostro DB
    mysql_select_db("my_teamup");

    //Riconoscimento utente
    $userid=$_SESSION["id"];

    /* impostiamo la query per riconoscere l'utente */
    $sqlquery "SELECT * FROM Users WHERE id='$userid'";
    $result mysql_query($sqlquery);
    $number mysql_num_rows($result);


    $i 0;
    if (
    $number 1) {
      print 
    "<center><p>Nessun utente riconosciuto</p></center>";
    }else{
      while (
    $number $i) {
        
    $usercode mysql_result($result,$i,"cod_utente");
        
    $i++;
      }

    $i=0;

    $nome=$_POST["nome"];
    $cognome=$_POST["cognome"];
    $compleanno=$_POST["compleanno"];
    $residenza=$_POST["residenza"];
    $cellulare=$_POST["cell"];
    $email=$_POST["email"];

    $form[]=$usercode;
    $form[]=$nome;
    $form[]=$cognome;
    $form[]=$compleanno;
    $form[]=$residenza;
    $form[]=$cell;
    $form[]=$email;

    $lenght=count($form);


    while (
    $lenght>=0){
        if(
    $form[$lenght]!=""){
        
    switch (
    $lenght) {
      case 
    0:
        
    $query="INSERT INTO personal_data(utente) VALUES ('$usercode')";
        break;
      case 
    1:
        
    $query="UPDATE personal_data SET nome='$nome' WHERE utente='$usercode'";
        break;
      case 
    2:
      
    $query="UPDATE personal_data SET cognome='$cognome' WHERE utente='$usercode'";   
      break;
      case 
    3:
        
    $query="UPDATE personal_data SET data_nascita='$compleanno' WHERE utente='$usercode'";
        break;
      case 
    4:
        
    $query="UPDATE personal_data SET residenza='$residenza' WHERE utente='$usercode'";
        break;
      case 
    5:
        
    $query="UPDATE personal_data SET mobile='$cellulare' WHERE utente='$usercode'";
        break;
      case 
    6:
        
    $query="UPDATE personal_data SET emai='$email' WHERE utente='$usercode'";
        break;
      case 
    7:
        break;
        }
        }
    $ins=mysql_query($query);
    --
    $lenght;    
    }
    $ref $_SERVER['HTTP_REFERER'];
    header('refresh: 0; url='.$ref);

    ?>

  2. #2
    alemoppo is offline AlterVista Staff
    Join Date
    Feb 2010
    Location
    IT
    Posts
    543

    Default

    You are using the deprecated fuction "mysql_*". Use mysqli_* or PDO.

    If you can speak italian, you can ask here: forum.it.altervista.org

    Bye!

  3. #3
    laravista is offline Utente AlterBlog
    Join Date
    Dec 2019
    Posts
    43

    Default

    Try Laravel

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

SEO by vBSEO