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

    Problema Con Update Multipli

    Ciao ho un problema nell'aggiornare dei dati con un aggiornamento multiplo.

    Ho una pagina (modifica.php) con un recordset paginato e filtrato che invia i dati via post alla pagina update.php che contiene il codice per fare l'aggiornamento
    Qui sotto il codice della pagina modifica.php


    <?php require_once('../Connections/connvoti.php'); ?>
    <?php
    if (!function_exists("GetSQLValueString")) {
    function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
    {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

    $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

    switch ($theType) {
    case "text":
    $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
    break;
    case "long":
    case "int":
    $theValue = ($theValue != "") ? intval($theValue) : "NULL";
    break;
    case "double":
    $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
    break;
    case "date":
    $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
    break;
    case "defined":
    $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
    break;
    }
    return $theValue;
    }
    }

    $colname_Recordset1 = "-1";
    if (isset($_GET['materia'])) {
    $colname_Recordset1 = $_GET['materia'];
    }
    $col1_Recordset1 = "-1";
    if (isset($_GET['classe'])) {
    $col1_Recordset1 = $_GET['classe'];
    }
    mysql_select_db($database_connvoti, $connvoti);
    $query_Recordset1 = sprintf("SELECT id, materia, classe, voto, alunno FROM tblvotiassenze WHERE materia = %s AND classe =%s", GetSQLValueString($colname_Recordset1, "text"),GetSQLValueString($col1_Recordset1, "text"));
    $Recordset1 = mysql_query($query_Recordset1, $connvoti) or die(mysql_error());
    $row_Recordset1 = mysql_fetch_assoc($Recordset1);
    $totalRows_Recordset1 = mysql_num_rows($Recordset1);

    // start a counter in order to number the input fields for each record
    $i = 0;
    ?>
    <!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>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Documento senza titolo</title>
    <script type="text/javascript">
    <!--
    function VF_form1(){ //v2.0



    var theForm = document.form1;
    var errMsg = "";
    var setfocus = "";

    if (theForm['oresvolte2'].value != ""){
    if (theForm['oresvolte2'].value != theForm['sss'].value){
    errMsg = "";
    setfocus = "['oresvolte2']";
    }
    }
    if (errMsg != ""){
    alert(errMsg);
    eval("theForm" + setfocus + ".focus()");
    }
    else theForm.submit();
    }
    //-->
    </script>
    </head>

    <body>



    <label></label>
    </p>

    <form id="namestoupdate" name="namestoupdate" method="post" action="update.php">
    <table border="0">
    <tr>
    <td></td>
    <td>materia</td>
    <td>classe</td>
    <td>voto</td>
    </tr>
    <?php do { ?>
    <tr>
    <td><?php echo $row_Recordset1['alunno']; ?></td>
    <td><?php echo $row_Recordset1['materia']; ?></td>
    <td><?php echo $row_Recordset1['classe']; ?></td>
    <td><label>
    <input name="voto" type="text" id="voto" value="<?php echo $row_Recordset1['voto']; ?>" />
    </label></td>
    </tr>
    <?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?>
    </table>



    <label> <?php
    {
    // add 1 to the count, close the loop, close the form, and the mysql connection
    ++$i;
    }?>
    <input type="submit" name="submit" id="submit" value="submit" />
    </label>
    <input name="id[$i]" type="hidden" id="id[$i]" value="<?php echo $row_Recordset1['id']; ?>" />
    </p>
    </form>

    </body>
    </html>

    <?php
    mysql_free_result($Recordset1);

    ?>


    quindi nella pagina update.php c'è il codice


    <?php
    // connect to the database
    $host="localhost"; // Host name
    $username="root"; // Mysql username
    $password=""; // Mysql password
    $db_name="votiseconda_versione"; // Database name
    $tbl_name="tblvotiassenze"; // Table name

    // Connect to server and select databse.
    mysql_connect("$host", "$username", "$password")or die("cannot connect");
    mysql_select_db("$db_name")or die("cannot select DB");

    // find out how many records there are to update
    $size = count($_POST['voto']);

    // start a loop in order to update each record
    $i = 0;
    while ($i < $size) {
    // define each variable
    $voto = $_POST['voto'][$i];
    $id = $_POST['id'][$i];


    // do the update and print out some info just to provide some visual feedback
    // you might need to remove the single quotes around the field names, for example bookinfo = '$bookinfo' instead of `bookinfo` = '$bookinfo'
    $query = "UPDATE tblvotiassenze SET voto = '$voto' WHERE id = '$id' LIMIT 1";
    mysql_query($query) or die ("Error in query: $query");
    print "$voto

    Updated!

    ";
    ++$i;
    }
    mysql_close();
    ?>


    ma mi da un messaggio di errore

    Notice: Uninitialized string offset: 0 in C:\wamp\www\VOTI CTS2\votiassenze\update.php on line 20

    Notice: Undefined offset: 0 in C:\wamp\www\VOTI CTS2\votiassenze\update.php on line 21


    cioè al codice


    // define each variable
    $voto = $_POST['voto'][$i];
    $id = $_POST['id'][$i];


    qualcuno può aiutarmi grazie mille sono disperato

    ciao

    A.

  2. #2
    Utente di HTML.it L'avatar di telegio
    Registrato dal
    Sep 2001
    Messaggi
    2,591
    io uso questo..
    nella prima pagina ho la checkbox dove recupero i valori
    Codice PHP:
    <input type="checkbox" name="<?php echo "item[]"?>" value="<?php echo $array[id]; ?>">
    Codice PHP:
    //questa è la variabile che assegni a TUTTI i valori selezionati
    $variabile $_POST['variabile'];
    mysql_connect("xxxxxxx","xxxxx","xxxxxx");

    // seleziona il database
    mysql_select_db($DB) or die("Unable to select database");
    if(
    $item>0) {
    foreach (
    $item as $id){
    if(
    strlen($id)>0){
    $query="UPDATE tabella SET campo = '$variabile' WHERE id = '$id' LIMIT 1";
    $dati=mysql_query("$query");
    if(
    $dati)echo"aggiornamento effettuato
    "
    ;
    else echo
    "aggiornamento non effettuato
    "
    ;
    }
    }

    prova..

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.