PHP多重功能更新不更新,并得到第1行空白 [英] PHP Multiple Update function not updating and gets the 1st row blank

查看:117
本文介绍了PHP多重功能更新不更新,并得到第1行空白的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先,我用PHP Dreamweaver将与phpMyAdmin数据库的程序。这一方案得到我的记录在第一排的空白,当我提交按钮,然后在一个行,其余的记录仍然存在这是第二排及以下,但在第1行中的记录仍然在数据库中,它为什么要发生?任何想法为我解决这个程序,它也不会更新我的纪录。这让我感到恶心,我需要帮助,请! :(
TNX ...

这是code:

 < PHP require_once('连接/ tlsc_conn.php');
  mysql_select_db($ database_tlsc_conn,$ tlsc_conn);
  $ query_Recordset1 =SELECT * FROM tbl_name表;
  $ Recordset1 =的mysql_query($ query_Recordset1,$ tlsc_conn)或死亡(mysql_error());
  $ row_Recordset1 = mysql_fetch_assoc($ Recordset1);
  $ totalRows_Recordset1 = mysql_num_rows($ Recordset1);  如果(使用isset($ _ POST ['提交'])){
      $数= COUNT($ _ POST ['身份证']);
      $提交= $ _GET ['身份证'];      为($ I = 0; $ I< $计数; $ I ++){
          $ SQL1 =UPDATE $ tbl_name表SET NAME ='$名称[$ i],姓氏='$姓氏[$ i]',电子邮件= $电子邮件[$ i]'WHERE ID ='$ ID [$ i] ';
          $ row_Recordset1 =的mysql_query($ SQL1);
       }    如果($ row_Recordset1){
            标题(位置:lulu.php);
            出口;
    }
 }
?>
!< D​​OCTYPE HTML PUBLIC - // W3C // DTD XHTML 1.0过渡// ENhttp://www.w3.org /TR/xhtml1/DTD/xhtml1-transitional.dtd\">
< HTML的xmlns =htt​​p://www.w3.org/1999/xhtml>
< HEAD>
 < META HTTP-EQUIV =Content-Type的CONTENT =text / html的;字符集= ISO-8859-1/>
 <标题>无标题文档< /标题>
< /头>
<身体GT;
  <表格名称=窗体2的方法=邮报行动=>
  <表格的宽度=634BORDER =1>
    &所述; TR>
       < TD> ID< / TD>
       < TD>名称和LT; / TD>
       < TD>姓氏< / TD>
       < TD>电子邮件< / TD>
    < / TR>
   < PHP做{&GT?;
    &所述; TR>
      < TD>< PHP的$ id [] = $ row_Recordset1 ['身份证']; ?>< PHP的echo $ row_Recordset1 ['身份证']; ?>
      <输入名称=ID []类型=隐藏值=< PHP的echo $ row_Recordset1 ['身份证'];?>中/>
      < / TD>
      &所述; TD>
        <输入名称=名称[]类型=文本VALUE =< PHP的echo $ row_Recordset1 ['名'];?>>
      < / TD>
      &所述; TD>
        <输入名称=姓氏[]类型=文本VALUE =< PHP的echo $ row_Recordset1 ['姓氏'];?>>
      < / TD>
      &所述; TD>
        <输入名字=电子邮件[]类型=文本VALUE =< PHP的echo $ row_Recordset1 [电子邮件];?>> < / TD>
    < / TR>
    < PHP}而($ row_Recordset1 = mysql_fetch_assoc($ Recordset1)); ?>
   < /表>
    &所述p为H.;
    <输入类型=提交名称=提交值=提交/>
    &所述; / P>
  < /表及GT;
   &所述p为H.;
   &所述; / P>
< /身体GT;
< / HTML>


解决方案

您需要把:

  $ NAME = array_map('mysql_real_escape_string',$ _ POST ['名']);
$姓氏= array_map('mysql_real_escape_string',$ _ POST ['姓氏']);
$电子邮件= array_map('mysql_real_escape_string',$ _ POST ['邮件']);
$ ID = array_map('mysql_real_escape_string',$ _ POST ['身份证']);

在你的循环。您使用的这些变量,但你永远充满他们从表单输入。

First of all, I use PHP Dreamweaver to make a program with phpMyAdmin Database. This program gets my records in a 1st row blank when I submit the button, and the remaining records in a rows are still there which is 2nd row and below, but the records in a 1st row is still on the database, why should it happen? any idea for me to solve this program, it also won't update my record. this makes me sick, i need help please! :( tnx...

this is the code:

<?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>
   </p>
</body>
</html>

解决方案

You need to put:

$name = array_map('mysql_real_escape_string', $_POST['name']);
$lastname = array_map('mysql_real_escape_string', $_POST['lastname']);
$email = array_map('mysql_real_escape_string', $_POST['email']);
$id = array_map('mysql_real_escape_string', $_POST['id']);

before your for loop. You're using these variables but you never filled them in from the form inputs.

这篇关于PHP多重功能更新不更新,并得到第1行空白的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆