-2
 <?php
    $host="localhost"; // Host name 
    $username="xxxx"; // Mysql username 
    $password="xxxx"; // Mysql password 
    $db_name="xxxx"; // Database name 
    $tbl_name="xxxx"; // 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 xxxx WHERE branch = 'xx' AND xxxx.semester=x ORDER BY xxxx.xxxx";
    $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"><strong>Id</strong></td>
    <td align="center"><strong>Name</strong></td>
    <td align="center"><strong>may_tc_s1</strong></td>
    <td align="center"><strong>may_ac_s1</strong></td>
    </tr>
    <?php
    // Check if button name "submit" is active, do this 
    if (isset($_POST['Submit'])) {
        $name = $_POST['name'];
        $lastname = $_POST['lastname'];
        $email = $_POST['email'];
    for($i=0;$i<$count;$i++){
    $sql1="UPDATE $tbl_name SET xxx='$name[$i]', xxx='$lastname[$i]', xxx='$email[$i]' WHERE xxx='$id[$i]'";
    $result1=mysql_query($sql1);
    }
    }
    if(isset($result1)){
    header("location:try.php");
    }
    ?>
    <?php
    while($rows=mysql_fetch_array($result)){
    ?>
    <tr>
    <td align="center"><?php $id[]=$rows['idatten']; ?><?php echo $rows['idatten']; ?></td>
    <td align="center"><input name="name[]" type="text" id="name" value="<?php echo $rows['username']; ?>"></td>
    <td align="center"><input name="lastname[]" type="text" id="lastname" value="<?php echo $rows['may_tc_s1']; ?>"></td>
    <td align="center"><input name="email[]" type="text" id="email" value="<?php echo $rows['may_ac_s1']; ?>"></td>
    </tr>
    <?php
    }
    ?>
    <tr>
    <td colspan="4" align="center"><input type="submit" name="submit" value="Submit"></td>
    </tr>
    </table>
    </td>
    </tr>
    </form>
    </table>

我可以在文本字段中看到记录,但新输入的值没有更新??????代码有问题吗??????尝试了各种方法,找不到任何正确的方法???

4

2 回答 2

0

参考这段代码:

extract($_POST);
if (isset($Submit)) 
 {
  for($i=0;$i<$count;$i++)
   {
    $update=("UPDATE tbl_name SET name='$name[$i]', lname='$lastname[$i]',email='$email[$i]' WHERE id='$id[$i]'");
    $res=mysql_query($update);
   }
 }
 if(isset($res))
  {
   header("location:try.php");
  }
?>
<?php
while($rows=mysql_fetch_array($result)){
?>
于 2013-09-21T07:28:28.490 回答
-1

您没有正确引用变量。

$sql1 = "UPDATE $tbl_name SET xxx='".$name[$i]."', xxx='".$lastname[$i]."', xxx='".$email[$i]."' WHERE xxx='".$id[$i]."'";
于 2013-09-21T07:14:56.510 回答