Visualizzazione dei risultati da 1 a 4 su 4

Discussione: errore update multiplo

  1. #1
    Utente di HTML.it
    Registrato dal
    Jun 2006
    Messaggi
    330

    errore update multiplo

    dovrebbe fare l'update multiplo ma..secondo voi perchè non funziona?

    Creo la tabella che poi devo modificare
    -------------------------------------------
    CREATE TABLE `test_mysql` (
    `id` int(4) NOT NULL auto_increment,
    `name` varchar(65) NOT NULL default '',
    `lastname` varchar(65) NOT NULL default '',
    `email` varchar(65) NOT NULL default '',
    PRIMARY KEY (`id`)
    ) TYPE=MyISAM AUTO_INCREMENT=7 ;
    -------------------------------------------

    Inserisco i valori
    -------------------------------------------------------------------------------
    INSERT INTO `test_mysql` VALUES (1, 'Billly', 'Blueton', 'bb5@phpeasystep.com');
    INSERT INTO `test_mysql` VALUES (2, 'Jame', 'Campbell', 'jame@somewhere.com');
    INSERT INTO `test_mysql` VALUES (3, 'Mark', 'Jackson', 'mark@phpeasystep.com');
    INSERT INTO `test_mysql` VALUES (4, 'Linda', 'Travor', 'lin65@phpeasystep.com');
    INSERT INTO `test_mysql` VALUES (5, 'Joey', 'Ford', 'fordloi@somewhere.com');
    INSERT INTO `test_mysql` VALUES (6, 'Sidney', 'Gibson', 'gibson@phpeasystep.com');
    -----------------------------------------------------------------------------------

    lo script che dovrebbe modificare i dati tramite i form
    -------------------------------------------------------
    Codice PHP:
    <?php
    $host
    ="localhost"// Host name 
    $username=""// Mysql username 
    $password=""// Mysql password 
    $db_name="test"// Database name 
    $tbl_name="test_mysql"// 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");

    $sql="SELECT * FROM $tbl_name";
    $result=mysql_query($sql);

    // Count table rows 
    $count=mysql_num_rows($result);
    ?>
    <table width="500" border="0" cellspacing="1" cellpadding="0">
    <form name="form1" method="post" action="">
    <tr> 
    <td>
    <table width="500" border="0" cellspacing="1" cellpadding="0">


    <tr>
    <td align="center">[b]Id[/b]</td>
    <td align="center">[b]Name[/b]</td>
    <td align="center">[b]Lastname[/b]</td>
    <td align="center">[b]Email[/b]</td>
    </tr>
    <?php
    while($rows=mysql_fetch_array($result)){
    ?>
    <tr>
    <td align="center"><? $id[]=$rows['id']; ?><? echo $rows['id']; ?></td>
    <td align="center"><input name="name[]" type="text" id="name" value="<? echo $rows['name']; ?>"></td>
    <td align="center"><input name="lastname[]" type="text" id="lastname" value="<? echo $rows['lastname']; ?>"></td>
    <td align="center"><input name="email[]" type="text" id="email" value="<? echo $rows['email']; ?>"></td>
    </tr>
    <?php
    }
    ?>
    <tr>
    <td colspan="4" align="center"><input type="submit" name="Submit" value="Submit"></td>
    </tr>
    </table>
    </td>
    </tr>
    </form>
    </table>
    <?php
    // Check if button name "Submit" is active, do this 
    if($Submit){
    for(
    $i=0;$i<$count;$i++){
    $sql1="UPDATE $tbl_name SET name='$name[$i]', lastname='$lastname[$i]', email='$email[$i]' WHERE id='$id[$i]'";
    $result1=mysql_query($sql1);
    }
    }

    if(
    $result1){
    header("location:update_multiple.php");
    }
    mysql_close();
    ?>
    -------------------------------------------------

    fate una prova, non riesco a trovare l'errore, (mancanza di esperienza)

  2. #2
    Probabilmente perchè utilizzi register globals, una funzione stra-deprecata e pericolosa dal punto di vista della sicurezza.

    Inoltre non esegui alcun controllo sull'input ne applichi mysql_real_escape_string() o funzione equivalente, etc. etc. etc.

  3. #3
    Utente di HTML.it
    Registrato dal
    Jun 2006
    Messaggi
    330
    come potrebbe essere modificata per farla funzionare, se non chiedo troppo, altrimenti grazie lo stesso

  4. #4
    Utente di HTML.it
    Registrato dal
    Jun 2006
    Messaggi
    330
    oppure esiste qualche modo per fare update multipli

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.