Alterando e salvando dados do usuário mysql em uma tabela de exibição que exibe os dados do usuário
Eu tenho uma tabela que exibe os dados do usuário buscados a partir de uma tabela mysql. Eu quero torná-lo editável dentro das células desta tabela. Eu usei o php para mostrar dados dentro dos campos de entrada do tipo "texto", conforme mostrado no código.
Para reenviar os dados alterados, agrupei a linha da tabela em um formulário, mas o problema é que os dados do formulário não são reenviados. Quero fazer com que o usuário altere seus detalhes e envie-o usando o botão "salvar dados do usuário", que não está enviando dados para atualização ao clicar e nem funciona como botão de envio. Eu tentei usar o onsubmit também. Por favor ajude.
<!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").v,alue;
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>
Meu editu.php está aqui >>
<?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" );
}
?>