Visualizzazione dei risultati da 1 a 5 su 5
  1. #1

    form con visualizzazione

    ciao ragazzi premetto che nn ho molte basi di php quindi cercate di essere il più chiaro possibili voglio creare un form che mi deve far registrare un utente e poi gli fa visualizzare i dati inseriti e me li salva nel mio database (a proposito per salvare i dati nel mio database mi creo a parte delle tabelle in mysql??? e se la risposta è si come lo collego con il codice???)il problema sta nel fatto che la pagina del form si vede ma dopo nella pagina successiva i dati nn vengono visualizzati. Chi mi spiega come posso fare?

    questo è il primo file che ho chiamato form.html
    codice:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    
    
    
    <html xmlns = "http://www.w3.org/1999/xhtml">
    <head>
    <title>Sample form to take user input in XHTML</title>
    </head>
    
    <body>
    <h1>This is a sample registration form.</h1>
    Please fill in all fields and click Register.
    
     
    <form method = "post" action = "form.php">
    <img src = "images/user.gif" alt = "User" />
    
     <span style = "color: blue">
     Please fill out the fields below.
    
     </span>
    
    <img src = "images/fname.gif" alt = "First Name" />
    <input type = "text" name = "fname" />
    
    
    <img src = "images/lname.gif" alt = "Last Name" />
    <input type = "text" name = "lname" />
    
    <img src = "images/email.gif" alt = "Email" />
    <input type = "text" name = "email" />
    
    <img src = "images/phone.gif" alt = "Phone" />
    <input type = "text" name = "phone" />
    
    
    <span style = "font-size: 10pt">
    Must be in the form (555)555-5555</span>
    
    
    
    
    <img src = "images/downloads.gif"
    alt = "Publications" />
    
    
    <span style = "color: blue">
    Which book would you like information about?
    </span>
    
    
    <select name = "book">
    <option>Internet and WWW How to Program 3e</option>
    <option>C++ How to Program 4e</option>
    <option>Java How to Program 5e</option>
    <option>XML How to Program 1e</option>
    </select>
    
    
    
    
    <img src = "images/os.gif" alt = "Operating System" />
    
    <span style = "color: blue">
     Which operating system are you currently using?
    
    </span>
    
    
     <input type = "radio" name = "os" value = "Windows XP"
     checked = "checked" />
     Windows XP
    
    <input type = "radio" name = "os" value =
    "Windows 2000" />
    Windows 2000
    
    <input type = "radio" name = "os" value =
    "Windows 98" />
    Windows 98
    
    <input type = "radio" name = "os" value = "Linux" />
     Linux
    
    <input type = "radio" name = "os" value = "Other" />
    Other
    
    
    
    <input type = "submit" value = "Register" />
    </form>
    
    </body>
    </html>
    questo è il secondo file che ho chiamato form.php
    codice:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">   <html xmlns = "http://www.w3.org/1999/xhtml"> <head> <title>Form Validation</title> </head> <body style = "font-family: arial,sans-serif"> <?php extract( $_POST ); // determine whether phone number is valid and print 18 // an error message if not if ( !ereg( "^\([0-9]{3}\)[0-9]{3}-[0-9]{4}$",  $phone ) ){print( "
    
    <span style = \"color: red;  font-size: 2em\">  INVALID PHONE NUMBER</span>
      A valid phone number must be in the form  (555)555-5555
      <span style = \"color: blue\">  Click the Back button, enter a valid phone  number and resubmit.
    
      Thank You.</span></p></body></html>" );   die(); // terminate script execution  }  ?>  
    
    Hi <span style = "color: blue">  <?php print( "$fname" ); ?>  </span>. Thank you for completing the survey.
     You have been added to the <span style = "color: blue">  <?php print( "$book " ); ?>   </span> mailing list. </p> The following information has been saved in our database:
     <table border = "0" cellpadding = "0" cellspacing = "10"> <tr> <td bgcolor = "#ffffaa">Name </td> <td bgcolor = "#ffffbb">Email</td> <td bgcolor = "#ffffcc">Phone</td> <td bgcolor = "#ffffdd">OS</td> </tr>  <tr> <?php // print each form field’s value print( "<td>$fname $lname</td> <td>$email</td> <td>$phone</td> <td>$os</td>" ); ?> </tr> </table> 
    
    
     <div style = "font-size: 10pt; text-align: center"> This is only a sample form. You have not been added to a mailing list. </div> </body> </html>
    Ringrazio anticipatamente tutti quelli che mi spiegano cosa fare o come fare....

    P.S. Potrei anche togliere la pagina che visualizza i dati (Form.php) ma mi rimane sempre il problema di salvare i dati. Grazie 1000
    I bravi programmatori sanno cosa scrivere, i migliori sanno cosa riscrivere (e riusare)

  2. #2
    nessuno sa niente???
    I bravi programmatori sanno cosa scrivere, i migliori sanno cosa riscrivere (e riusare)

  3. #3
    Utente di HTML.it
    Registrato dal
    Mar 2007
    Messaggi
    1,611
    di sapere so solo che per spiegarti tutto occorrono ore

    detto in poche parole:

    inizializzi tutte le variabili così

    codice:
    $fname = isset($_POST['fname']) ? $_POST['fname'] : '';
    poi ci metti questa variabile in ogni input ad esempio così:

    codice:
    <input type="text" name="fname" value="'.$fname.'" />
    nell'action del form ci metti quindi la stessa pagina in cui è il form, quindi form.php

    una volta cliccato su submit mandi tutto alla stessa pagina ma dato che hai inviato tutto in post ti troverai i dati compilati...

    a questo punto puoi inviare tutto ad una pagina nuova, o la stessa gestendo le varie condizioni, che contiene le istruzioni mysql che archivieranno i dati

    questo è quello che dovresti fare a grandi linee, spero di esserti stato di aiuto.

    NON ABBANDONATE CANI O GATTI!!!

  4. #4
    ok... ma ho problemi in sql nn capisco se devo crearmi un database esterno al sito... oppure con il php è possibile creare un database e delle cartelle dove inserire i file degli utenti??? il mio più grande problema è che nn capisco come fare ad salvare i dati in sql con il php. Grazie per la risposta
    I bravi programmatori sanno cosa scrivere, i migliori sanno cosa riscrivere (e riusare)

  5. #5
    Utente di HTML.it
    Registrato dal
    Mar 2007
    Messaggi
    1,611
    datti un'occhiata qui http://php.html.it/guide/leggi/101/guida-php-pratica/

    e qui http://php.html.it/guide/leggi/77/gu...mysql-pratica/

    sono fatte bene

    senza delle nozioni difficilmente riuscirai a fare qualcosa

    buon lavoro
    NON ABBANDONATE CANI O GATTI!!!

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.