佳礼资讯网

 找回密码
 注册

ADVERTISEMENT

查看: 1067|回复: 4

要如何把submit button variable post去另一个page?

[复制链接]
发表于 6-8-2013 11:46 AM | 显示全部楼层 |阅读模式
不知道我有发错区域吗,如果是请纠正我谢谢
我有个php  page 是这样的
有不同的edit button就会post 不同row的value




可是无论我按那个edit button都会停留在第三个记录,以下是我的问题

在图一,我按了第一个edit button,应该是要显示第一个row的资料
可是却显示出第三个,无论我按第一或第二,都会显示出第三的资料

我的用的是while loop,如果只停留在三的话,那就代表loop的时候有问题,还是有别的方法可以用?
以下是图一的code
  1.     <html>
  2.     <head>
  3.     <meta charset="utf-8">
  4.     <title>Kinhock Traktor</title>
  5.     <link href="style/fg_membersite.css" rel='stylesheet' type='text/css'>
  6.     </head>
  7.     <?php
  8.     session_start();
  9.             include('adminconfig.php');
  10.             $ID = $_SESSION['ID']; //get posted data
  11.         $name = $_SESSION['name'];
  12.             $password = $_SESSION['password'];
  13.             $department = $_SESSION['department'];
  14.             $email = $_SESSION['email'];
  15.       
  16.         $sql=" SELECT * FROM admin WHERE ID='$ID'";
  17.       $result=mysql_query($sql);
  18.     ?>
  19.             
  20.     <body>
  21.     <form method="POST" action="adminsave.php" onSubmit="return validate(this)">
  22.     <table id="edit" class="btn">
  23.     <tr>
  24.     <td id='fcolor2' style='border:2px solid red' align=center> ID </td>
  25.        <td id='fcolor2' style='border:2px solid red' align=center> Name </td>
  26.        <td id='fcolor2' style='border:2px solid red' align=center> Password </td>
  27.        <td id='fcolor2' style='border:2px solid red; width:auto;' align=center> Department </td>
  28.        <td id='fcolor2' style='border:2px solid red' align=center> Email </td></tr>
  29.     <tr>
  30.     <td><input type = 'text' name="ID" value='<?php echo $ID ?>' maxlength="50"></td>
  31.     <td><input type = 'text' name="name" value='<?php echo $name ?>' maxlength="50"></td>
  32.     <td><input type = 'text' name="password" value='<?php echo $password ?>' maxlength=50"></td>
  33.     <td><input type = 'text' name="department" value='<?php echo $department ?>' maxlength="50"></td>
  34.     <td><input type = 'text' name="email" value='<?php echo $email ?>' style='width:300px' " maxlength="50"></td></tr>
  35.     <tr id="btn"><td><input id='btn'type='submit' name='Submit' value='Submit' /></td></tr>
  36.     </table>
  37.     </form>
  38.     <?php
  39.       $sql=" SELECT * FROM admin WHERE ID='$ID'";
  40.       $result=mysql_query($sql);
  41.     ?>
  42.     </body>
  43.     </html>
复制代码
回复

使用道具 举报


ADVERTISEMENT

发表于 6-8-2013 02:34 PM | 显示全部楼层
你第一张图的source code呢?
回复

使用道具 举报

 楼主| 发表于 6-8-2013 03:07 PM | 显示全部楼层
hui_wooi 发表于 6-8-2013 02:34 PM
你第一张图的source code呢?

抱歉,第一张的在这里

<!doctype html>
<head>
<meta charset="utf-8">
<title>Admin Database </title>

<link href="style/fg_membersite.css" rel='stylesheet' type='text/css'>
  <style>
        body {               
                font-family: Helvetica,Arial,sans-serif;
                color:#333333;
                font-size:13px;
                background-image:url(/kinhock/bluesky.jpg);
        }
        
    h1{
                font-family: 'Droid Serif', Georgia, Times, serif;
                font-size: 28px;               
        }
        
        a{
                color: #0071D8;
                text-decoration:none;
        }
        
        a:hover{
                text-decoration:underline;
        }

        :focus {
                outline: 0;
        }
        
        p{
                color:#D00000;
        }
        
        #wrap{
                width: auto;
                margin:0 auto;                                
                overflow:auto;               
        }
        
        #content{
                background: #f7f7f7;
                border-radius: 10px;
        }
        
        #editable {               
                padding: 10px;               
        }
        
        #status{
                display:none;
                margin-bottom:15px;
                padding:5px 10px;
                border-radius:5px;
        }
        
        .success{
                background: #B6D96C;
        }
        
        .error{
                background: #ffc5cf;
        }
        
        #footer{
                margin-top:15px;
                text-align: center;
        }
        
        #save{        
                display: none;
                right: 50px;
                margin: 5px 10px 10px;               
                outline: none;
                cursor: pointer;        
                text-align: center;
                text-decoration: none;
                font: 12px/100% Arial, Helvetica, sans-serif;
                font-weight:700;        
                padding: 5px 10px;        
                -webkit-border-radius: 5px;
                -moz-border-radius: 5px;
                border-radius: 5px;        
                color: #606060;
                border: solid 1px #b7b7b7;        
                background: #fff;
                background: -webkit-gradient(linear, left top, left bottom, from(#fff), to(#ededed));
                background: -moz-linear-gradient(top,  #fff,  #ededed);
                filter:  progidXImageTransform.Microsoft.gradient(startColorstr='#ffffff', endColorstr='#ededed');
        }        
        
        #save:hover
        {
        background: #ededed;
                background: -webkit-gradient(linear, left top, left bottom, from(#fff), to(#dcdcdc));
                background: -moz-linear-gradient(top,  #fff,  #dcdcdc);
                filter:  progidXImageTransform.Microsoft.gradient(startColorstr='#ffffff', endColorstr='#dcdcdc');
        }
        
    </style>
  
  <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js" type="text/javascript"></script>
  <script>
    $(document).ready(function() {
               
                $("#save".click(function (e) {                        
                        var content = $('#editable').html();        
                                
                        $.ajax({
                                url: 'adminsave.php',
                                type: 'POST',
                                data: {
                content: content
                                },                                
                                success:function (data) {
                                                        
                                        if (data == '1')
                                        {
                                                $("#status"
                                                .addClass("success"
                                                .html("Data received successfully."
                                                .fadeIn('fast')
                                                .delay(3000)
                                                .fadeOut('slow');        
                                        }
                                        else
                                        {
                                                $("#status"
                                                .addClass("error"
                                                .html("An error occured, the data could not be saved"
                                                .fadeIn('fast')
                                                .delay(3000)
                                                .fadeOut('slow');        
                                        }
                                }
                        });   
                        
                });
               
                $("#editable".click(function (e) {
                        $("#save".show();
                        e.stopPropagation();
                });
        
                $(document).click(function() {
                        $("#save".hide();  
                });
        
        });

</script>
</head>
<?php
session_start();
include('adminconfig.php');


$sql = "SELECT * FROM admin ORDER BY ID";
$result = mysql_query($sql);  
?>


<body>
<div id="wrap">
<div id="status"></div>
<form method="OST" action="adminsave.php">
   <table class="viewdb"  contentEditable="true">
   <tr><td id='fcolor' style='border:2px solid black' align=center> ID </td>
   <td id='fcolor' style='border:2px solid black' align=center> Name </td>
   <td id='fcolor' style='border:2px solid black' align=center> Password </td>
   <td id='fcolor' style='border:2px solid black; width:auto;' align=center> Department </td>
   <td id='fcolor' style='border:2px solid black' align=center> Email </td></tr>
        <div id="content">
        <?php

while($row = mysql_fetch_array($result)){ ?>
        <tr>
        <td style='border:2px solid black; width:auto' align=center><?php echo $row['ID'] ?> </td>
        <td style='border:2px solid black' align=center> <?php echo  $row['name']  ?> </td>
        <td style='border:2px solid black' align=center> <?php echo $row['password']  ?> </td>
        <td style='border:2px solid black; width:200px' align=center> <?php echo $row['department'] ?> </td>
        <td style='border:2px solid black' align=center> <?php echo $row['email'] ?> </td>

        <tr>
<td><input id='edit' type = 'text' name="ID[]" value='<?php echo ($row['ID']); ?>' maxlength="50"/></td>
<td><input id='edit' type = 'text' name="name[]" value='<?php echo $row['name'] ?>' maxlength="50"></td>
<td><input id='edit' type = 'text' name="password[]" value='<?php echo $row['password'] ?>' maxlength=50"></td>
<td><input id='edit' type = 'text' name="department[]" value='<?php echo $row['department'] ?>' maxlength="50"></td>
<td><input id='edit' type = 'text' name="email[]" value='<?php echo $row['email'] ?>' style='width:300px' " maxlength="50"></td>
<?php } ?>
<td><input id='edit' type='submit' name='submit' value='Submit' /></td></tr>
        </table>
        </form>
<?php
    $ID=$row['ID'];
        $name=$row['name'];
        $password=$row['password'];
        $department=$row['department'];
        $email=$row['email'];
        ?>
        </div>
</div>
</body>
</html>

现在我编制了
现在图一的变成酱
Untitled3.png
本帖最后由 silentkill89 于 6-8-2013 03:20 PM 编辑

回复

使用道具 举报

发表于 6-8-2013 03:32 PM | 显示全部楼层
怎么好像越改越奇怪的?
所以你修改后的东西,是你要的?可以成功运作?
回复

使用道具 举报

 楼主| 发表于 6-8-2013 05:08 PM | 显示全部楼层
hui_wooi 发表于 6-8-2013 03:32 PM
怎么好像越改越奇怪的?
所以你修改后的东西,是你要的?可以成功运作?

可以运作了
viewadmindb.php
  1. <!doctype html>
  2. <head>
  3. <meta charset="utf-8">
  4. <title>Admin Database </title>

  5. <link href="style/fg_membersite.css" rel='stylesheet' type='text/css'>
  6.   <style>
  7.         body {               
  8.                 font-family: Helvetica,Arial,sans-serif;
  9.                 color:#333333;
  10.                 font-size:13px;
  11.                 background-image:url(/kinhock/bluesky.jpg);
  12.         }
  13.        
  14.     h1{
  15.                 font-family: 'Droid Serif', Georgia, Times, serif;
  16.                 font-size: 28px;               
  17.         }
  18.        
  19.         a{
  20.                 color: #0071D8;
  21.                 text-decoration:none;
  22.         }
  23.        
  24.         a:hover{
  25.                 text-decoration:underline;
  26.         }

  27.         :focus {
  28.                 outline: 0;
  29.         }
  30.        
  31.         p{
  32.                 color:#D00000;
  33.         }
  34.        
  35.         #wrap{
  36.                 width: auto;
  37.                 margin:0 auto;                               
  38.                 overflow:auto;               
  39.         }
  40.        
  41.         #content{
  42.                 background: #f7f7f7;
  43.                 border-radius: 10px;
  44.         }
  45.        
  46.         #editable {               
  47.                 padding: 10px;               
  48.         }
  49.        
  50.         #status{
  51.                 display:none;
  52.                 margin-bottom:15px;
  53.                 padding:5px 10px;
  54.                 border-radius:5px;
  55.         }
  56.        
  57.         .success{
  58.                 background: #B6D96C;
  59.         }
  60.        
  61.         .error{
  62.                 background: #ffc5cf;
  63.         }
  64.        
  65.         #footer{
  66.                 margin-top:15px;
  67.                 text-align: center;
  68.         }
  69.        
  70.         #save{       
  71.                 display: none;
  72.                 right: 50px;
  73.                 margin: 5px 10px 10px;               
  74.                 outline: none;
  75.                 cursor: pointer;       
  76.                 text-align: center;
  77.                 text-decoration: none;
  78.                 font: 12px/100% Arial, Helvetica, sans-serif;
  79.                 font-weight:700;       
  80.                 padding: 5px 10px;       
  81.                 -webkit-border-radius: 5px;
  82.                 -moz-border-radius: 5px;
  83.                 border-radius: 5px;       
  84.                 color: #606060;
  85.                 border: solid 1px #b7b7b7;       
  86.                 background: #fff;
  87.                 background: -webkit-gradient(linear, left top, left bottom, from(#fff), to(#ededed));
  88.                 background: -moz-linear-gradient(top,  #fff,  #ededed);
  89.                 filter:  progid:DXImageTransform.Microsoft.gradient(startColorstr='#ffffff', endColorstr='#ededed');
  90.         }       
  91.        
  92.         #save:hover
  93.         {
  94.         background: #ededed;
  95.                 background: -webkit-gradient(linear, left top, left bottom, from(#fff), to(#dcdcdc));
  96.                 background: -moz-linear-gradient(top,  #fff,  #dcdcdc);
  97.                 filter:  progid:DXImageTransform.Microsoft.gradient(startColorstr='#ffffff', endColorstr='#dcdcdc');
  98.         }
  99.        
  100.     </style>
  101.   
  102.   <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js" type="text/javascript"></script>
  103.   <script>
  104.     $(document).ready(function() {
  105.                
  106.                 $("#save").click(function (e) {                       
  107.                         var content = $('#editable').html();       
  108.                                
  109.                         $.ajax({
  110.                                 url: 'adminsave.php',
  111.                                 type: 'POST',
  112.                                 data: {
  113.                 content: content
  114.                                 },                               
  115.                                 success:function (data) {
  116.                                                        
  117.                                         if (data == '1')
  118.                                         {
  119.                                                 $("#status")
  120.                                                 .addClass("success")
  121.                                                 .html("Data received successfully.")
  122.                                                 .fadeIn('fast')
  123.                                                 .delay(3000)
  124.                                                 .fadeOut('slow');       
  125.                                         }
  126.                                         else
  127.                                         {
  128.                                                 $("#status")
  129.                                                 .addClass("error")
  130.                                                 .html("An error occured, the data could not be saved")
  131.                                                 .fadeIn('fast')
  132.                                                 .delay(3000)
  133.                                                 .fadeOut('slow');       
  134.                                         }
  135.                                 }
  136.                         });   
  137.                        
  138.                 });
  139.                
  140.                 $("#editable").click(function (e) {
  141.                         $("#save").show();
  142.                         e.stopPropagation();
  143.                 });
  144.        
  145.                 $(document).click(function() {
  146.                         $("#save").hide();  
  147.                 });
  148.        
  149.         });

  150. </script>
  151. </head>
  152. <?php
  153. session_start();
  154. include('adminconfig.php');


  155. $sql = "SELECT * FROM admin ORDER BY ID";
  156. $result = mysql_query($sql);  
  157. ?>


  158. <body>
  159. <div id="wrap">
  160. <div id="status"></div>
  161. <form method="POST" action="adminsave.php" onSubmit="return validate(this);">
  162.    <table class="viewdb"  contentEditable="true">
  163.    <tr><td id='fcolor' style='border:2px solid black' align=center> ID </td>
  164.    <td id='fcolor' style='border:2px solid black' align=center> Name </td>
  165.    <td id='fcolor' style='border:2px solid black' align=center> Password </td>
  166.    <td id='fcolor' style='border:2px solid black; width:auto;' align=center> Department </td>
  167.    <td id='fcolor' style='border:2px solid black' align=center> Email </td></tr>
  168.         <div id="content">
  169.         <?php

  170. while($row = mysql_fetch_array($result)){ ?>
  171.         <tr>
  172.         <td style='border:2px solid black; width:auto' align=center><?php echo $row['ID'] ?> </td>
  173.         <td style='border:2px solid black' align=center> <?php echo  $row['name']  ?> </td>
  174.         <td style='border:2px solid black' align=center> <?php echo $row['password']  ?> </td>
  175.         <td style='border:2px solid black; width:200px' align=center> <?php echo $row['department'] ?> </td>
  176.         <td style='border:2px solid black' align=center> <?php echo $row['email'] ?> </td>

  177.         <tr>
  178. <td><input class='edit' type = 'text' name="ID[]" value='<?php echo $row['ID']; ?>' maxlength="50"/></td>
  179. <td><input class='edit' type = 'text' name="name[]" value='<?php echo $row['name'] ?>' maxlength="50"></td>
  180. <td><input class='edit' type = 'text' name="password[]" value='<?php echo $row['password'] ?>' maxlength=50"></td>
  181. <td><input class='edit' type = 'text' name="department[]" value='<?php echo $row['department'] ?>' maxlength="50"></td>
  182. <td><input class='edit' type = 'text' name="email[]" value='<?php echo $row['email'] ?>' style='width:300px' " maxlength="50"></td>
  183. <?php } ?>
  184. <td><input id='edit' type='submit' name='submit' value='Submit' /></td></tr>
  185.         </table>
  186.         </form>
  187. <?php
  188.     $ID=$row['ID'];
  189.         $name=$row['name'];
  190.         $password=$row['password'];
  191.         $department=$row['department'];
  192.         $email=$row['email'];
  193.        
  194.        
  195.         ?>
  196.        
  197.         </div>
  198. </div>
  199. </body>
  200. </html>
复制代码
adminsave.php
  1. <?php
  2. session_start();
  3. include('adminconfig.php');

  4. $ids=$_POST['ID'];
  5. $name_arr=$_POST['name'];
  6. $password_arr=$_POST['password'];
  7. $department_arr=$_POST['department'];
  8. $email_arr=$_POST['email'];

  9. foreach($ids as $key=>$id) {
  10.      $name = $name_arr[$key];
  11.          $password = $password_arr[$key];
  12.          $department = $department_arr[$key];
  13.          $email = $email_arr[$key];
  14.         $sql = "UPDATE `admin` SET `name` = '{$name}', `password` = '{$password}', `department` = '{$department}', `email` = '{$email}' WHERE `ID` = '{$id}'";
  15.         $result = mysql_query($sql);
  16.         }
  17.     if(!$result){
  18.        die('invalid query:'.mysql_error());
  19.          }
  20. else
  21. echo ("<tr><td>" . "Data updated succesfully..." . "</td></tr>");
  22. header('Refresh:5; url=viewadmindb.php');
  23. die;

  24. ?>
复制代码
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

 

ADVERTISEMENT



ADVERTISEMENT



ADVERTISEMENT

ADVERTISEMENT


版权所有 © 1996-2023 Cari Internet Sdn Bhd (483575-W)|IPSERVERONE 提供云主机|广告刊登|关于我们|私隐权|免控|投诉|联络|脸书|佳礼资讯网

GMT+8, 20-9-2025 07:21 AM , Processed in 0.121176 second(s), 30 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表