问题描述
我有一个表显示从mysql表中获取的用户数据。我希望在该表的单元格内对其进行编辑。我使用php在text类型输入字段中显示数据,如代码所示。
I have a table which displays user-data fetched from a mysql table.i want to make it editable right within the cells of this table. I have used php to show data inside "text" type input fields as shown in the code.
为了重新提交已更改的数据,我已将表格行包装在内表单,但问题是表单数据不会重新提交。我想让用户更改他的详细信息并使用保存用户数据按钮提交它,该按钮既不发送用于点击更新的数据也不用作提交按钮。我也试过使用onsubmit。请帮忙。
In order to resubmit the changed data, I have wrapped the table row within a form, but the issue is that the form data is not resubmitted. I want to make the user change his details and submit it using "save user data" button which is neither sending data for updation-on-click and nor working as submit button. I tried using onsubmit also. Please help.
<!DOCTYPE html>
<html>
<head>
<title>SAS User Info
</title>
<script>
function chgform(){
var frm = document.createElement("FORM");
var v0 = document.getElementById("ser").value;
var v1 = document.getElementById("name").value;
var v2 = document.getElementById("typo").value;
var v3 = document.getElementById("email").value;
frm.ser.value = v0;
frm.name.value = v1;
frm.typo.value = v2;
frm.email.value = v3;
frm.action='editu.php';
frm.submit();
};
</script>
<?php
require('connect.php');
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$user = $_POST['userlist'];
$queryU = "SELECT ser, username, user_type, email FROM `user` WHERE username = '$user'";
$listU = $connection->query($queryU);
if ($listU->num_rows > 0){
while($rowu = $listU->fetch_assoc()) {
$s = $rowu['ser'] ;
$u = $rowu['username'] ;
$t = $rowu['user_type'] ;
$e = $rowu['email'] ;
$tt = NULL;
if($t=="Administrator"){$tt = "checked"; $z=NULL;}
else {$z = "checked";}
}
}
else {
$s = $t = $u = $e = 'Nil';
}
}
?>
<style>
body{
margin: 0;
padding: 0;
background: transparent;
font-family: Arial;
font-size: 22px;
color: #000;
}
input[type=email], input[type=text]{
background: transparent;
border: 1px solid rgba(255,255,255,0.6);
border-radius: 2px;
//color: #fff;
font-family: 'Exo', sans-serif;
font-size: 22px;
font-weight: 400;
padding: 4px;
-webkit-placeholder-color: white;
}
.bkg{
position: absolute;
top: -20px;
left: -20px;
right: -40px;
bottom: -40px;
width: auto;
background-image: url("main.jpg");
height: 800px;
background-size: cover;
-webkit-filter: blur(2px);
z-index: 0;
}
::-webkit-input-placeholder{
color: rgba(255,255,255,.8);
font-family: Helvetica;
}
.grad{
position: absolute;
top: -20px;
left: -20px;
right: -40px;
bottom: -40px;
width: auto;
height: 800px;
background: -webkit-gradient(linear, left top, left bottom, color-stop(20%,rgba(0,0,0,0)), color-stop(100%,rgba(10,10,10,0.65)));
z-index: 1;
opacity: 0.7;
}
.header{
position: fixed;
top: calc(35% - 35px);
left: calc(32% - 255px);
z-index: 2;
}
.nav{
position: fixed;
top: calc(40% - 75px);
left: calc(25% - 255px);
height: 250px;
width: 270px;
padding: 10px;
z-index: 1;
background-color:rgba(75, 75, 75, 0.5);
}
.vuser{
position: absolute;
top: calc(40% - 75px);
left: calc(38% - 90px);
height: 250px;
width: 926px;
padding: 10px;
z-index: 2;
background-color:rgba(75, 75, 75, 0.5);
}
.header div{
float: left;
height:auto;
color: #fff;
font-family: 'Exo', sans-serif;
font-size: 45px;
font-weight: 300;
}
input[type=button]{
width: 260px;
height: 35px;
background: #fff;
border: 1px solid #fff;
cursor: pointer;
border-radius: 2px;
color: #a18d6c;
font-family: 'Exo', sans-serif;
font-size: 16px;
font-weight: 700 ;
padding: 6px;
margin-top: 10px;
}
input[type=button]:hover,
input[type=submit]:hover, input[type=reset]:hover{
opacity: 0.8;
}
input[type=button]:active{
opacity: 0.6;
}
input[type=password]:focus,input[type=text]:focus,
input[type=email]:focus
{
border: 15px solid rgba(255,255,255,0.9);
}
}
::-moz-input-placeholder{
color: rgba(255,0,0,1);
}
.style2 {
font-weight: bold}
.style6 {
font-weight: bold}
.style8 {
font-weight: bold}
.style10 {
font-weight: bold}
</style>
</head>
<body>
<div class="bkg">
</div>
<div class="grad">
</div>
<div class="header">
<div>SAS
</div>
</div>
<br>
<div class="nav" id="nav">
<br>
<br>
<br>
<br>
<input type="button" id="bkp" onclick="window.location='panel.php'" value="Back to Control Panel">
<input type="button" id="bkm" onclick="window.location='index.html'" value="Back to Main">
<input type="button" id="sub" type="submit" onsubmit="chgform()" value="Save User Data">
</div>
<div class="vuser" id="vuser">
<table id="tab" width="928" style="opacity: 0.9;" height="250" border="1" bordercolor="#666666" bgcolor="#FFFFFF">
<tr align="undefined" valign="top" bgcolor="#2693ff">
<th height="62" colspan="4" align="center" valign="middle" class="style2" scope="col">
<p style="margin-top: 0; margin-bottom: 0;;">
</p>
<p style="margin-top: 0; margin-bottom: 0;;">User Registeration Data
</p>
</th>
</tr>
<tr valign="top">
<th width="35" height="62" align="center" valign="middle" class="style26" scope="col">
<strong>Ser
</strong>
</th>
<th width="200" align="center" valign="middle" class="style26 style6" scope="col">
<p style="margin-top: 0; margin-bottom: 0;">Username
</p>
</th>
<th width="200" align="center" valign="middle" class="style26 style8" scope="col">
<p style="margin-top: 0; margin-bottom: 0;">User Type
</p>
</th>
<th width="365" align="center" valign="middle" class="style26 style10" scope="col">
<p style="margin-top: 0; margin-bottom: 0;">Email
</p>
</th>
</tr>
<tr valign="top">
<form name="data" id="data" method="GET" action="editu.php" >
<th height="59" align="center" valign="middle" id = "ser" name="ser" class="style26" scope="row">
<?php echo $s ?>
</th>
<th align="center" valign="middle" class="style26" scope="row">
<div align="center">
<input type="text" style="margin-top: 0; margin-bottom: 0;" name="name" id="name" maxlength="15" size="15" pattern="[a-z,A-Z,0-9]{5,15}" value="<?php echo $u ?>" required>
</input>
</div>
</th>
<th align="left" valign="left" class="style26">
<input type="radio" style="margin-top: 0; margin-bottom: 0;" name="typo" id="typo" value="<?php echo $t ?>"
<?php echo $tt; ?> required>Administrator
</radio>
<br>
<input type="radio" style="margin-top: 0; margin-bottom: 0;" name="typo" id="typo" value="<?php echo $t ?>"
<?php echo $z; ?>" required>User
</radio>
</th>
<th align="center" valign="middle" class="style26">
<div align="center">
<input style="margin-top: 0; margin-bottom: 0;" type="email" name="email" maxlength="30" size="30" placeholder="Enter your email" value="<?php echo $e ?>" required>
</input>
</div>
</th>
</tr>
</form>
</table>
</div>
</body>
</html>
我的editu.php在这里>>
My editu.php is here>>
<?php
require('connect.php');
if ($_SERVER['REQUEST_METHOD'] === 'GET') {
$ser = $_GET['ser'];
$usr = $_GET['name'];
$typ = $_GET['typo'];
$eml = $_GET['email'];
$chg = "UPDATE `user` SET `username` = '$usr' , `usertype` = '$typ' ,
`email` = '$eml' WHERE `ser` = '$ser' ";
$upd = $connection->query($chg);
header( "refresh:1; url=viewuser.php" );
}
?>
推荐答案
我通过处理表单提交来管理工作。但是至少在调查这个问题时,我感谢所有。错误是:1。我没有把提交放在任何表格标签的前提下,也没有在点击时使用.submit()处理它。
2我正在使用按钮类型两次..作为按钮b。作为提交
I managed the job by handling the form submission.However, I appreciate all for at least looking into this question.The errors were: 1. i didnt put the submit in any form tag premises and nor did i handle it using .submit() on click.
2. i was using type of button twice.. a. as "button" b. as "submit"
这篇关于在视图中更改和保存mysql用户数据显示用户数据的表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!