查看: 1067|回复: 4
|
要如何把submit button variable post去另一个page?
[复制链接]
|
|
不知道我有发错区域吗,如果是请纠正我谢谢
我有个php page 是这样的
有不同的edit button就会post 不同row的value

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

在图一,我按了第一个edit button,应该是要显示第一个row的资料
可是却显示出第三个,无论我按第一或第二,都会显示出第三的资料
我的用的是while loop,如果只停留在三的话,那就代表loop的时候有问题,还是有别的方法可以用?
以下是图一的code- <html>
- <head>
- <meta charset="utf-8">
- <title>Kinhock Traktor</title>
- <link href="style/fg_membersite.css" rel='stylesheet' type='text/css'>
- </head>
- <?php
- session_start();
- include('adminconfig.php');
- $ID = $_SESSION['ID']; //get posted data
- $name = $_SESSION['name'];
- $password = $_SESSION['password'];
- $department = $_SESSION['department'];
- $email = $_SESSION['email'];
-
- $sql=" SELECT * FROM admin WHERE ID='$ID'";
- $result=mysql_query($sql);
- ?>
-
- <body>
- <form method="POST" action="adminsave.php" onSubmit="return validate(this)">
- <table id="edit" class="btn">
- <tr>
- <td id='fcolor2' style='border:2px solid red' align=center> ID </td>
- <td id='fcolor2' style='border:2px solid red' align=center> Name </td>
- <td id='fcolor2' style='border:2px solid red' align=center> Password </td>
- <td id='fcolor2' style='border:2px solid red; width:auto;' align=center> Department </td>
- <td id='fcolor2' style='border:2px solid red' align=center> Email </td></tr>
- <tr>
- <td><input type = 'text' name="ID" value='<?php echo $ID ?>' maxlength="50"></td>
- <td><input type = 'text' name="name" value='<?php echo $name ?>' maxlength="50"></td>
- <td><input type = 'text' name="password" value='<?php echo $password ?>' maxlength=50"></td>
- <td><input type = 'text' name="department" value='<?php echo $department ?>' maxlength="50"></td>
- <td><input type = 'text' name="email" value='<?php echo $email ?>' style='width:300px' " maxlength="50"></td></tr>
- <tr id="btn"><td><input id='btn'type='submit' name='Submit' value='Submit' /></td></tr>
- </table>
- </form>
- <?php
- $sql=" SELECT * FROM admin WHERE ID='$ID'";
- $result=mysql_query($sql);
- ?>
- </body>
- </html>
复制代码 |
|
|
|
|
|
|
|
发表于 6-8-2013 02:34 PM
|
显示全部楼层
|
|
|
|
|
|
|

楼主 |
发表于 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: progid XImageTransform.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: progid XImageTransform.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>
现在我编制了
现在图一的变成酱
本帖最后由 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- <!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: progid:DXImageTransform.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: progid:DXImageTransform.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="POST" action="adminsave.php" onSubmit="return validate(this);">
- <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 class='edit' type = 'text' name="ID[]" value='<?php echo $row['ID']; ?>' maxlength="50"/></td>
- <td><input class='edit' type = 'text' name="name[]" value='<?php echo $row['name'] ?>' maxlength="50"></td>
- <td><input class='edit' type = 'text' name="password[]" value='<?php echo $row['password'] ?>' maxlength=50"></td>
- <td><input class='edit' type = 'text' name="department[]" value='<?php echo $row['department'] ?>' maxlength="50"></td>
- <td><input class='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>
复制代码 adminsave.php- <?php
- session_start();
- include('adminconfig.php');
- $ids=$_POST['ID'];
- $name_arr=$_POST['name'];
- $password_arr=$_POST['password'];
- $department_arr=$_POST['department'];
- $email_arr=$_POST['email'];
- foreach($ids as $key=>$id) {
- $name = $name_arr[$key];
- $password = $password_arr[$key];
- $department = $department_arr[$key];
- $email = $email_arr[$key];
- $sql = "UPDATE `admin` SET `name` = '{$name}', `password` = '{$password}', `department` = '{$department}', `email` = '{$email}' WHERE `ID` = '{$id}'";
- $result = mysql_query($sql);
- }
- if(!$result){
- die('invalid query:'.mysql_error());
- }
- else
- echo ("<tr><td>" . "Data updated succesfully..." . "</td></tr>");
- header('Refresh:5; url=viewadmindb.php');
- die;
- ?>
复制代码 |
|
|
|
|
|
|
| |
本周最热论坛帖子
|