0

这个程序现在允许我连续更新记录,有人可以解决这个问题吗?

这是代码:我为此使用 Dreamweaver

PHP 代码:需要更多答案

<?php require_once('Connections/tlsc_conn.php');
 mysql_select_db($database_tlsc_conn, $tlsc_conn);
  $query_Recordset1 = "SELECT * FROM tbl_name";
 $Recordset1 = mysql_query($query_Recordset1, $tlsc_conn) or die(mysql_error());

  $totalRows_Recordset1 = mysql_num_rows($Recordset1);


 if(isset($_POST['submit'])) {

//    $count = count($_POST['id']);
//  $count=mysql_num_rows($Recordset1);
    $submit = $_GET['submit'];
$i = ($_POST['count']);
$name = ($_POST['name']);
$lastname = ($_POST['lastname']);
$email = ($_POST['email']);
$id = ($_POST['id']);

    for($i=0;$i<$count;$i++){

        $sql1="UPDATE $tbl_name SET name='$name[$i]', lastname='$lastname[$i]', email='$email[$i]' WHERE id='$id[$i]'";

        $row_Recordset1=mysql_query($sql1);
    }

    if($row_Recordset1){
            header("location:lulu.php");
            exit;
    }   
 }


?>

HTML 代码:我不认为它是否已修复,但我认为它是...

<!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=iso-8859-1" />
 <title>Untitled Document</title>
</head>

<body>
  <form name="form2" method="post" action="">
  <table width="634" border="1">
    <tr>
       <td>id</td>
       <td>name</td>
       <td>lastname</td>
       <td>email</td>
    </tr>

<?php while($row_Recordset1 = mysql_fetch_assoc($Recordset1)){ ?> 
    <tr>
      <td><?php $id[]=$row_Recordset1['id']; ?><?php echo $row_Recordset1['id']; ?> 
      <input name="id[]" type="hidden" value="<?php echo $row_Recordset1['id'];   ?>" />
      </td>
      <td>
        <input name="name[]" type="text" value="<?php echo $row_Recordset1['name']; ?>">                       
      </td>
      <td>
        <input name="lastname[]" type="text" value="<?php echo $row_Recordset1['lastname']; ?>">
      </td>
      <td>
        <input name="email[]" type="text" value="<?php echo  $row_Recordset1['email']; ?>">       </td>
    </tr>
    <?php }  ?>  
   </table>
    <p>
    <input type="submit" name="submit" value="Submit" />
    </p>
  </form>
   <p>
</body>
</html>
4

3 回答 3

3
$sql1="UPDATE $tbl_name

没有名为 的变量$tbl_name,因此您的查询失败:它不知道要更新哪个表,这是语法错误。

于 2013-09-19T08:01:03.817 回答
3

上面的代码中没有带有 $tbl_name 的变量。正确使用这个变量,它就会起作用。

<?php
$i = ($_POST['count']);
$name = ($_POST['name']);
$lastname = ($_POST['lastname']);
$email = ($_POST['email']);
$id = ($_POST['id']);
$tbl_name = ???

$sql1="UPDATE $tbl_name SET name='$name[$i]', lastname='$lastname[$i]', email='$email[$i]' WHERE id='$id[$i]'";

?>

于 2013-09-19T08:59:38.487 回答
0

在循环内打开和关闭表单

于 2013-09-19T08:01:54.757 回答