1

まず、PHP Dreamweaver を使用して、phpMyAdmin データベースでプログラムを作成します。ボタンを送信すると、このプログラムは最初の行の空白のレコードを取得し、行の残りのレコードはまだ2行目以下にありますが、1行目のレコードはまだデータベースにあります。 ? このプログラムを解決するためのアイデアはありませんが、記録も更新されません。これは私を病気にします、私は助けが必要です! tnx...

<?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()); 
  $row_Recordset1 = mysql_fetch_assoc($Recordset1); 
  $totalRows_Recordset1 = mysql_num_rows($Recordset1); 

  if(isset($_POST['submit'])) { 
      $count = count($_POST['id']); 
      $submit = $_GET['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; 
    }    
 } 
?>

<!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 do { ?> 
    <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 } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?>  
   </table>
    <p>
    <input type="submit" name="submit" value="Submit" />
    </p>
  </form>
   <p>
</body>
</html>
4

2 に答える 2

0

最初にこれを 5 行目から削除します。

  $row_Recordset1 = mysql_fetch_assoc($Recordset1); // I think this not valid it should be only in loop

次のようにwhileループで試してください:

 <?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>
于 2013-09-19T07:31:33.427 に答える
0

loopingwhileの代わりに に変更しますdo-while。生成された html を確認print_r($_POST)し、フォームの送信後に .html の構造を確認しますpost arraymysqlior PDOas の使用mysqlは非推奨になりました。

編集:

<?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 }  ?>
于 2013-09-19T07:09:17.563 に答える