Visualizzazione dei risultati da 1 a 8 su 8

Discussione: Form checkbox sql

  1. #1
    Utente di HTML.it
    Registrato dal
    Jul 2009
    Messaggi
    12

    Form checkbox sql

    Salve a tutti il mio dannato script continua a dare errori e io non so piu dove sbattere la testa
    vi posto umilmente gli errori e il codice...

    ERRORI

    Notice: Undefined index: lc# in C:\Programmi\EasyPHP 3.0\www\c\mod.php on line 4

    Notice: Undefined index: l.net in C:\Programmi\EasyPHP 3.0\www\c\mod.php on line 5

    Notice: Undefined index: lvb in C:\Programmi\EasyPHP 3.0\www\c\mod.php on line 6

    Notice: Undefined index: lcobol in C:\Programmi\EasyPHP 3.0\www\c\mod.php on line 7

    Notice: Undefined index: labap/4 in C:\Programmi\EasyPHP 3.0\www\c\mod.php on line 8

    Notice: Undefined index: lsap in C:\Programmi\EasyPHP 3.0\www\c\mod.php on line 9

    Notice: Undefined index: lcisco in C:\Programmi\EasyPHP 3.0\www\c\mod.php on line 10

    Notice: Undefined index: lpython in C:\Programmi\EasyPHP 3.0\www\c\mod.php on line 11

    Notice: Undefined index: lflash in C:\Programmi\EasyPHP 3.0\www\c\mod.php on line 12

    Notice: Undefined index: ljava in C:\Programmi\EasyPHP 3.0\www\c\mod.php on line 13

    Notice: Undefined index: lphp in C:\Programmi\EasyPHP 3.0\www\c\mod.php on line 14

    Notice: Undefined index: lsql in C:\Programmi\EasyPHP 3.0\www\c\mod.php on line 15

    Notice: Undefined index: lplsql in C:\Programmi\EasyPHP 3.0\www\c\mod.php on line 16

    Notice: Undefined index: lmysql in C:\Programmi\EasyPHP 3.0\www\c\mod.php on line 17

    Notice: Undefined index: linguaggi in C:\Programmi\EasyPHP 3.0\www\c\mod.php on line 32
    Error: Il numero delle colonne non corrisponde al conteggio alla riga 1


    FORM

    <form name="MyForm" action="mod.php" method="POST">
    <table>
    <tr>
    <th rowspan="3">Dati della Risorsa</th>
    <td>Nome <input type="text" name="nome"></td>
    <td>Cognome <input type="text" name="cognome"></td>
    </tr>
    <tr>
    <td>Data di Nascita <input type="text" name="nascita"> (es. 25/03/1981)</td>
    <td>eMail <input type="text" name="email"></td>

    </tr>
    <tr>
    <td>Residenza <input type="text" name="residenza"></td>
    <td>Telefono <input type="text" name="telefono"></td>
    </tr>
    <tr>
    <th rowspan="3">Esperienze della Risorsa</th>
    <td>Esperienze Lavorative (una per ogni riga)
    <textarea name="esp_lavorative" rows="20" cols="50"></textarea></td>
    <td>Esperienze Scolastiche (una per ogni riga)
    <textarea name="esp_scolastiche" rows="20" cols="50"></textarea></td>
    </tr>
    <tr>
    <td colspan="2">Curriculum Vitae <input type="file" name="cv"></td>
    </tr>
    <tr>
    <td colspan="2">Linguaggi
    <input type="checkbox" name="lc" value="c">C
    <input type="checkbox" name="lc++" value="c_plus">C++
    <input type="checkbox" name="lc#" value="c_sharp">C#
    <input type="checkbox" name="l.net" value=".net">.NET
    <input type="checkbox" name="lvb" value="vb">VB
    <input type="checkbox" name="lcobol" value="cobol">COBOL
    <input type="checkbox" name="labap/4" value="abap/4">ABAP/4
    <input type="checkbox" name="lsap" value="sap">SAP
    <input type="checkbox" name="lcisco" value="cisco">CISCO
    <input type="checkbox" name="lpython" value="python">PYTHON
    <input type="checkbox" name="lflash" value="flash">FLASH
    <input type="checkbox" name="ljava" value="java">JAVA
    <input type="checkbox" name="lphp" value="php">PHP
    <input type="checkbox" name="lsql" value="sql">SQL
    <input type="checkbox" name="lplsql" value="plsql">PLSQL
    <input type="checkbox" name="lmysql" value="mysql">MYSQL
    </td>
    <tr>
    <th>Contatto con la Risorsa</th>
    <td>Data Contatto <input type="text" name="data_contatto"> (es. 25/03/1981)</td>
    <td colspan="2">Esito
    <input type="radio" name="esito" value="positivo" checked>Positivo
    <input type="radio" name="esito" value="negativo">Negativo
    </td>
    </tr>
    <tr>
    <th>Aggiungi la Risorsa</th>
    <td colspan="2"><center><input type="submit" name="add" value="Aggiungi Risorsa"></center></td>
    </tr>
    </tr>


    </table>
    </form>

    MOD.php

    <?php
    $c=$_POST['lc'];
    $cpiu=$_POST['lc++'];
    $csharp=$_POST['lc#'];
    $net=$_POST['l.net'];
    $vb=$_POST['lvb'];
    $cobol=$_POST['lcobol'];
    $abap=$_POST['labap/4'];
    $sap=$_POST['lsap'];
    $cisco=$_POST['lcisco'];
    $py=$_POST['lpython'];
    $fl=$_POST['lflash'];
    $jv=$_POST['ljava'];
    $php=$_POST['lphp'];
    $sqly=$_POST['lsql'];
    $plsql=$_POST['lplsql'];
    $mysql=$_POST['lmysql'];

    $stringa = $c. " " .$cpiu. " " .$csharp. " " .$net. " " .$vb. " " .$cobol. " " .$abap. " " .$sap. " " .$cisco. " " .$py. " " .$fl. " " .$jv. " " .$php. " " .$sqly. " " .$plsql. " " .$mysql. " ".$mysql;

    #$section = mysql_escape_string($_POST['lc']);
    $con = mysql_connect("localhost","root","mysql");
    if (!$con)
    {
    die('Could not connect: ' . mysql_error());
    }

    mysql_select_db("fastinformatica", $con);

    $sql="INSERT INTO dipendenti (nome, cognome, nascita, email, residenza, telefono, esp_lavorative, esp_scolastiche, data_contatto, esito)
    VALUES
    ('$_POST[nome]','$_POST[cognome]','$_POST[nascita]','$_POST[email]','$_POST[residenza]','$_POST[telefono]','$_POST[esp_lavorative]','$_POST[esp_scolastiche]','$_POST[linguaggi]','$_POST[data_contatto]','$_POST[esito]')";
    $query = "INSERT INTO dipendenti (linguaggi) VALUES ('$stringa')";
    if (!mysql_query($sql,$con))
    {
    die('Error: ' . mysql_error());
    }
    #Qui eseguo un redirect all'home page
    echo"Risorsa aggiunta..." . '<meta http-equiv="refresh" content="10;url=http://localhost/c/gestionale.php">';
    #header("location: http://localhost/c/gestionale.php");
    mysql_close($con)
    ?>
    </div>
    </body>
    </html>

  2. #2
    Utente di HTML.it
    Registrato dal
    Sep 2001
    Messaggi
    892
    Dunque: i notice dipendono dall'error reporting level sul php.ini

    Hai due strade: o inizializzi tutte le variabili (quindi anche quelle vuote non valorizzate dall'utente che non ha checkato i box) oppure cambi via script l'error reporting level in questo modo (scelta un po' poco professionale):

    ini_set("error_reporting",0);

    da inserire ad inizio codice, e lui non ti stampa i notice.

    Per quanto riguarda l'errore, invece, hai dimenticato la colonna "linguaggi" nella query di inserimento...

  3. #3
    Utente di HTML.it
    Registrato dal
    Jul 2009
    Messaggi
    12
    si però non mi aggiunge comunque nel campo linguaggi del db i linguaggi...
    grazie comunque

  4. #4
    Utente di HTML.it
    Registrato dal
    Sep 2001
    Messaggi
    892
    Per quanto riguarda l'errore, invece, hai dimenticato la colonna "linguaggi" nella query di inserimento...

  5. #5
    Utente di HTML.it
    Registrato dal
    Jul 2009
    Messaggi
    12
    no perchè ho rimodificato i file ora te li posto.
    Grazie dell'aiuto mi stai salvando le chiappette


    Notice: Undefined index: lc++ in C:\Programmi\EasyPHP 3.0\www\c\mod.php on line 3

    Notice: Undefined index: lnet in C:\Programmi\EasyPHP 3.0\www\c\mod.php on line 5

    Notice: Undefined index: lvb in C:\Programmi\EasyPHP 3.0\www\c\mod.php on line 6

    Notice: Undefined index: lcobol in C:\Programmi\EasyPHP 3.0\www\c\mod.php on line 7

    Notice: Undefined index: labap/4 in C:\Programmi\EasyPHP 3.0\www\c\mod.php on line 8

    Notice: Undefined index: lsap in C:\Programmi\EasyPHP 3.0\www\c\mod.php on line 9

    Notice: Undefined index: lcisco in C:\Programmi\EasyPHP 3.0\www\c\mod.php on line 10

    Notice: Undefined index: lpython in C:\Programmi\EasyPHP 3.0\www\c\mod.php on line 11

    Notice: Undefined index: lflash in C:\Programmi\EasyPHP 3.0\www\c\mod.php on line 12

    Notice: Undefined index: ljava in C:\Programmi\EasyPHP 3.0\www\c\mod.php on line 13

    Notice: Undefined index: lphp in C:\Programmi\EasyPHP 3.0\www\c\mod.php on line 14

    Notice: Undefined index: lsql in C:\Programmi\EasyPHP 3.0\www\c\mod.php on line 15

    Notice: Undefined index: lplsql in C:\Programmi\EasyPHP 3.0\www\c\mod.php on line 16

    Notice: Undefined index: lmysql in C:\Programmi\EasyPHP 3.0\www\c\mod.php on line 17
    Error: Field 'linguaggi' doesn't have a default value


    FORM

    <form name="MyForm" action="mod.php" method="POST">
    <table>
    <tr>
    <th rowspan="3">Dati della Risorsa</th>
    <td>Nome <input type="text" name="nome"></td>
    <td>Cognome <input type="text" name="cognome"></td>
    </tr>
    <tr>
    <td>Data di Nascita <input type="text" name="nascita"> (es. 25/03/1981)</td>
    <td>eMail <input type="text" name="email"></td>

    </tr>
    <tr>
    <td>Residenza <input type="text" name="residenza"></td>
    <td>Telefono <input type="text" name="telefono"></td>
    </tr>
    <tr>
    <th rowspan="3">Esperienze della Risorsa</th>
    <td>Esperienze Lavorative (una per ogni riga)
    <textarea name="esp_lavorative" rows="20" cols="50"></textarea></td>
    <td>Esperienze Scolastiche (una per ogni riga)
    <textarea name="esp_scolastiche" rows="20" cols="50"></textarea></td>
    </tr>
    <tr>

    </tr>
    <tr>
    <td colspan="2">Linguaggi
    <input type="checkbox" name="lc" value="c">C
    <input type="checkbox" name="lc++" value="c_plus">C++
    <input type="checkbox" name="lc#" value="c_sharp">C#
    <input type="checkbox" name="lnet" value=".net">.NET
    <input type="checkbox" name="lvb" value="vb">VB
    <input type="checkbox" name="lcobol" value="cobol">COBOL
    <input type="checkbox" name="labap/4" value="abap/4">ABAP/4
    <input type="checkbox" name="lsap" value="sap">SAP
    <input type="checkbox" name="lcisco" value="cisco">CISCO
    <input type="checkbox" name="lpython" value="python">PYTHON
    <input type="checkbox" name="lflash" value="flash">FLASH
    <input type="checkbox" name="ljava" value="java">JAVA
    <input type="checkbox" name="lphp" value="php">PHP
    <input type="checkbox" name="lsql" value="sql">SQL
    <input type="checkbox" name="lplsql" value="plsql">PLSQL
    <input type="checkbox" name="lmysql" value="mysql">MYSQL
    </td>
    <tr>
    <th>Contatto con la Risorsa</th>
    <td>Data Contatto <input type="text" name="data_contatto"> (es. 25/03/1981)</td>
    <td colspan="2">Esito
    <input type="radio" name="esito" value="positivo" checked>Positivo
    <input type="radio" name="esito" value="negativo">Negativo
    </td>
    </tr>
    <tr>
    <th>Aggiungi la Risorsa</th>
    <td colspan="2"><center><input type="submit" name="add" value="Aggiungi Risorsa"></center></td>
    </tr>
    </tr>


    </table>
    </form>

    MOD

    <?php
    $c=$_POST['lc'];
    $cpiu=$_POST['lc++'];
    $csharp=$_POST['lc#'];
    $net=$_POST['lnet'];
    $vb=$_POST['lvb'];
    $cobol=$_POST['lcobol'];
    $abap=$_POST['labap/4'];
    $sap=$_POST['lsap'];
    $cisco=$_POST['lcisco'];
    $py=$_POST['lpython'];
    $fl=$_POST['lflash'];
    $jv=$_POST['ljava'];
    $php=$_POST['lphp'];
    $sqly=$_POST['lsql'];
    $plsql=$_POST['lplsql'];
    $mysql=$_POST['lmysql'];

    $stringa = $c . " " . $cpiu . " " . $csharp . " " . $net . " " . $vb . " " . $cobol . " " . $abap . " " . $sap . " " . $cisco . " " . $py . " " . $fl . " " . $jv . " " . $php . " " . $sqly . " " . $plsql . " " . $mysql;

    #$section = mysql_escape_string($_POST['lc']);
    $con = mysql_connect("localhost","root","mysql");
    if (!$con)
    {
    die('Could not connect: ' . mysql_error());
    }

    mysql_select_db("fastinformatica", $con);

    $sql="INSERT INTO dipendenti (nome, cognome, nascita, email, residenza, telefono, esp_lavorative, esp_scolastiche, data_contatto, esito)
    VALUES
    ('$_POST[nome]','$_POST[cognome]','$_POST[nascita]','$_POST[email]','$_POST[residenza]','$_POST[telefono]','$_POST[esp_lavorative]','$_POST[esp_scolastiche]','$_POST[data_contatto]','$_POST[esito]')";
    $query = "INSERT INTO dipendenti (linguaggi) VALUES ('$stringa')";
    if (!mysql_query($sql,$con))
    {
    die('Error: ' . mysql_error());
    }
    #Qui eseguo un redirect all'home page
    echo"Risorsa aggiunta..." . '<meta http-equiv="refresh" content="10;url=http://localhost/c/gestionale.php">';
    #header("location: http://localhost/c/gestionale.php");
    mysql_close($con)
    ?>
    </div>
    </body>
    </html>

  6. #6
    Utente di HTML.it
    Registrato dal
    Sep 2001
    Messaggi
    892
    No, è un modo cervellotico e poco efficace. La soluzione migliore è molto banale:

    // creo una variabile unica per la stringa linguaggi:
    $linguaggi="$c $cpiu $csharp $net $vb $cobol $abap ecc." (magari separa le variabili con una virgola o come ti pare)


    // effettuo l'insert:

    $sql="INSERT INTO dipendenti (nome, cognome, nascita, email, residenza, telefono, esp_lavorative,linguaggi , esp_scolastiche, data_contatto, esito)
    VALUES
    ('$_POST[nome]','$_POST[cognome]','$_POST[nascita]','$_POST[email]','$_POST[residenza]','$_POST[telefono]','$_POST[esp_lavorative]','$linguaggi','$_POST[esp_scolastiche]','$_POST[data_contatto]','$_POST[esito]')"

  7. #7
    Utente di HTML.it
    Registrato dal
    Jul 2009
    Messaggi
    12
    ma la variabile $stringa che ho creato per linguaggi va bene no? devo modificare solo l'insert scusa la mia ignoranza

  8. #8
    Utente di HTML.it
    Registrato dal
    Jul 2009
    Messaggi
    12
    TI AMO C****o santo

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 © 2025 vBulletin Solutions, Inc. All rights reserved.