Я хочу получить идентификатор данных в php, чтобы обновить их в моей базе данных. Я перепробовал много вещей, которые нашел в Интернете, но не смог решить проблему. Вот ВСЕ код для редактирования.
Здесь отображаются сообщения, но я не знаю, как получить идентификатор для каждого сообщения, чтобы люди могли редактировать / редактировать mysql
<?php
$link = mysqli_connect ('localhost', 'root', '', '');
mysqli_select_db ($link, 'CodersHome');
?>
<?php
session_start ();
if( !isset($_SESSION['username']))
header('location:../login.php');
?>
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title>CodersHome Agenda</title>
<link rel="shortcut icon" type="image/png" href="../tabimg.png">
<meta name="viewport" content="width=device-width,initial-scale=1">
<link rel="stylesheet" href="profile/profile.css">
<link rel="stylesheet" type="text/css" href="../navbar/navbar.css">
<link rel="stylesheet" type="text/css" href="agendacss/agendap.css">
<link rel="stylesheet" type="text/css" href="agendacss/agendacard.css">
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.11.2/css/all.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/4.1.1/normalize.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script src="https://use.fontawesome.com/d1341f9b7a.js"></script>
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<script src="https://cdn.jsdelivr.net/npm/darkmode-js@1.5.5/lib/darkmode-js.min.js"></script>
<script src="https://cdn.ckeditor.com/4.14.0/standard/ckeditor.js"></script>
<script src="agendatabs.js" charset="utf-8"></script>
</head>
<?php include '../navbar/navbar.html' ?>
<body>
<div id="page-container">
<div id="content-wrap">
<ul class="tab">
<li><a href="#" class="tablinks active" onclick="openCity(event, 'agenda')"><strong>Agenda</strong></a></li>
<li><a href="#" class="tablinks" onclick="openCity(event, 'createagenda')"><strong>Crea Agenda</strong></a></li>
</ul>
<br>
<div id="agenda" class="tabcontent">
<div class="welcome">
<h1 class="weltitle">Agenda 1er D</h1>
</div>
<br><hr><br>
<?php
$result = mysqli_query($link,"SELECT * FROM agenda");
while($row = mysqli_fetch_array($result)) {
//echo $row["title"];
//echo $row["description"];
//echo $row["datef"];
?>
<?php $i=0; ?>
<div class="row">
<div class="column">
<div class="card">
<?php echo $row["description"]; ?>
<?php echo $row["datef"]; ?>                                                                                                                                                                                         <?php echo $row["inserter"]; ?> <?php if($_SESSION['username'] == 'admin') { include('eddel.php');
} ?> <br>
</div>
</div>
</div>
<br>
<?php
$i++;
}
?>
</div>
Здесь вы можете увидеть, где я пытаюсь обновить.
<?php
session_start ();
$link = mysqli_connect ('localhost', 'root', '', '');
mysqli_select_db ($link, '');
if($link === false){
die("ERROR: Could not connect. " . mysqli_connect_error());
}
$title = $_POST ['title'];
$desc = $_POST ['editor1'];
$date1 = $_POST ['date1'];
$inserter = $_SESSION['username'];
$result = mysqli_query($link,"SELECT * FROM agenda");
while($row = mysqli_fetch_array($result)) {
//echo $row["title"];
//echo $row["description"];
//echo $row["datef"];
$i=0;
}
$sql = "UPDATE agenda SET title = $title, description = $desc, datef = $date1, inserter = $inserter WHERE id = $row[id]; ";
$i++;
if(mysqli_query($link, $sql)){
header("Refresh:0; url=agenda.php");
}
?>
<?php
if( !isset($_SESSION['username']))
header('location:../login.php');
?>
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title>CodersHome Agenda</title>
<link rel="shortcut icon" type="image/png" href="../tabimg.png">
<meta name="viewport" content="width=device-width,initial-scale=1">
<link rel="stylesheet" href="profile/profile.css">
<link rel="stylesheet" type="text/css" href="../navbar/navbar.css">
<link rel="stylesheet" type="text/css" href="agendacss/agendap.css">
<link rel="stylesheet" type="text/css" href="agendacss/agendacard.css">
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.11.2/css/all.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/4.1.1/normalize.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script src="https://use.fontawesome.com/d1341f9b7a.js"></script>
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<script src="https://cdn.jsdelivr.net/npm/darkmode-js@1.5.5/lib/darkmode-js.min.js"></script>
<script src="https://cdn.ckeditor.com/4.14.0/standard/ckeditor.js"></script>
<script src="agendatabs.js" charset="utf-8"></script>
</head>
<?php include '../navbar/navbar.html' ?>
<body>
<div class="welcome2">
<p class="weltitle">Edita Una Agenda</p>
</div>
<br><hr><br>
<form class="agfrm" action="agendaedit.php" method="post">
<div class="form-group">
<label>Title</label> <br> <br>
<input type="text" name="title" class="form-control" required><br> <br>
</div>
<div class="form-group">
<label>Description</label> <br> <br>
<textarea name="editor1" required></textarea>
<script>
CKEDITOR.replace( 'editor1' );
</script> <br> <br>
</div>
<label>Date</label> <br> <br>
<input type="date" id="date1" name="date1"
value="2020-02-25"
min="2020-01-01" max="2021-12-31" required> <br>
<br>
<button type="submit" class="homepbtn1">Sumbit</button>
</form>
</div>
</div>
</body>
</html>
<?php include '../Footer/index.html'?>
Я хочу обновить данные в таблице. У меня также есть идентификатор, назначенный для каждой строки, но я не знаю, как получить идентификатор для редактирования точной строки таблицы.
Также здесь приведена живая демонстрация того, где сообщение создается и воспроизводится.
function openCity(evt, cityName) {
var i, tabcontent, tablinks;
tabcontent = document.getElementsByClassName("tabcontent");
for (i = 0; i < tabcontent.length; i++) {
tabcontent[i].style.display = "none";
}
tablinks = document.getElementsByClassName("tablinks");
for (i = 0; i < tablinks.length; i++) {
tablinks[i].className = tablinks[i].className.replace(" active", "");
}
document.getElementById(cityName).style.display = "block";
evt.currentTarget.className += " active";
}
body {
background-color: white;
height: 96vh;
background-position: center;
background-size: cover;
background-repeat: no-repeat;
}
.welcome {
border: 2px solid black;
color: #7d3caf;
margin-top: 40px;
margin-left: 40px;
margin-right: 40px;
border-radius: 40px;
transition: 0.5s ease;
font-weight: 5em;
font-family: 'Century Gothic', sans-serif;
background-color: #f1f1f1;
}
.welcome:hover
{
border: 1px solid #6747c7 ;
background-color: #6747c7;
color: white;
font-weight: bold;
font-family: 'Century Gothic', sans-serif;
}
.weltitle {
text-align: center;
font-family: monospace;
font-size: 30px;
margin-bottom: 30px;
}
.weldis {
font-family: 'Century Gothic', sans-serif;
text-align: center;
}
.gtac {
text-align: center;
font-family: monospace;
}
.gtacl {
text-align: center;
}
.gtac1:hover {
color: black;
background-color: black;
border: 2px solid black;
}
.lbtn {
font-size: 20px;
text-decoration: none;
color: #fff;
padding: 5px 20px;
border: 1px solid #fff;
transition: 0.6s ease
}
.lbtn:hover{
background-color: #7a7979;
color: white;
font-size: 24px;
}
.span1 {
height: 40px;
}
.homepbtn1 {
top: 50%;
left: 80%;
background-color: #36344d;
margin-right: 20px;
font-size: 18px;
text-decoration: none;
color: #fff;
padding: 5px 20px;
transition: 0.6s ease;
border-radius: 10px;
cursor: pointer;
}
.homepbtn1:hover {
background-color: #7a7979;
color: white;
background-color: #FF5A36;
border-radius: 50px;
}
.btnmargin1 {
height: 60px;
}
.btnmargin2 {
height: 60px;
}
.extraspace {
height: 6px;
}
.weltitle {
text-align: center;
font-family: monospace;
font-size: 36px;
}
.weldis {
font-family: 'Century Gothic', sans-serif;
}
ul.tab {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
border: 1px solid #ccc;
background-color: #f1f1f1;
}
/* Float the list items side by side */
ul.tab li {float: left;}
/* Style the links inside the list items */
ul.tab li a {
display: inline-block;
color: black;
text-align: center;
padding: 14px 16px;
text-decoration: none;
transition: 0.3s;
font-size: 17px;
}
/* Change background color of links on hover */
ul.tab li a:hover {
background-color: #ddd;
}
/* Create an active/current tablink class */
ul.tab li a:focus, .active {
background-color: #ccc;
}
/* Style the tab content */
.tabcontent {
display: none;
padding: 6px 12px;
-webkit-animation: fadeEffect 1s;
animation: fadeEffect 1s;
}
div[class*="tabcontent"]:first-of-type {
display: block;
}
@-webkit-keyframes fadeEffect {
from {opacity: 0;}
to {opacity: 1;}
}
@keyframes fadeEffect {
from {opacity: 0;}
to {opacity: 1;}
}
/* Dropdown Button */
.dbtn {
color: black;
font-size: 30px;
border: none;
background-color: transparent;
cursor: pointer;
}
/* The container <div> - needed to position the dropdown content */
.ddown {
position: relative;
display: inline-block;
}
/* Dropdown Content (Hidden by Default) */
.dcon {
display: none;
font-size: 16px;
position: absolute;
background-color: #f1f1f1;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
z-index: 1;
}
/* Links inside the dropdown */
.dcon a {
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
}
/* Change color of dropdown links on hover */
.dcon a:hover {background-color: #ddd;}
/* Show the dropdown menu on hover */
.ddown:hover .dcon {display: block;}
/* Change the background color of the dropdown button when the dropdown content is shown */
.down:hover .dbtn {background-color: transparent;}
body {
background-color: white;
height: 96vh;
background-position: center;
background-size: cover;
background-repeat: no-repeat;
}
.welcome {
border: 2px solid black;
color: #7d3caf;
margin-top: 40px;
margin-left: 40px;
margin-right: 40px;
border-radius: 40px;
transition: 0.5s ease;
font-weight: 5em;
font-family: 'Century Gothic', sans-serif;
background-color: #f1f1f1;
}
.welcome:hover
{
border: 1px solid #6747c7 ;
background-color: #6747c7;
color: white;
font-weight: bold;
font-family: 'Century Gothic', sans-serif;
}
.weltitle {
text-align: center;
font-family: monospace;
font-size: 30px;
margin-bottom: 30px;
}
.weldis {
font-family: 'Century Gothic', sans-serif;
text-align: center;
}
.gtac {
text-align: center;
font-family: monospace;
}
.gtacl {
text-align: center;
}
.gtac1:hover {
color: black;
background-color: black;
border: 2px solid black;
}
.lbtn {
font-size: 20px;
text-decoration: none;
color: #fff;
padding: 5px 20px;
border: 1px solid #fff;
transition: 0.6s ease
}
.lbtn:hover{
background-color: #7a7979;
color: white;
font-size: 24px;
}
.span1 {
height: 40px;
}
.homepbtn1 {
top: 50%;
left: 80%;
background-color: #36344d;
margin-right: 20px;
font-size: 18px;
text-decoration: none;
color: #fff;
padding: 5px 20px;
transition: 0.6s ease;
border-radius: 10px;
cursor: pointer;
}
.homepbtn1:hover {
background-color: #7a7979;
color: white;
background-color: #FF5A36;
border-radius: 50px;
}
.btnmargin1 {
height: 60px;
}
.btnmargin2 {
height: 60px;
}
.extraspace {
height: 6px;
}
.weltitle {
text-align: center;
font-family: monospace;
font-size: 36px;
}
.weldis {
font-family: 'Century Gothic', sans-serif;
}
ul.tab {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
border: 1px solid #ccc;
background-color: #f1f1f1;
}
/* Float the list items side by side */
ul.tab li {float: left;}
/* Style the links inside the list items */
ul.tab li a {
display: inline-block;
color: black;
text-align: center;
padding: 14px 16px;
text-decoration: none;
transition: 0.3s;
font-size: 17px;
}
/* Change background color of links on hover */
ul.tab li a:hover {
background-color: #ddd;
}
/* Create an active/current tablink class */
ul.tab li a:focus, .active {
background-color: #ccc;
}
/* Style the tab content */
.tabcontent {
display: none;
padding: 6px 12px;
-webkit-animation: fadeEffect 1s;
animation: fadeEffect 1s;
}
div[class*="tabcontent"]:first-of-type {
display: block;
}
@-webkit-keyframes fadeEffect {
from {opacity: 0;}
to {opacity: 1;}
}
@keyframes fadeEffect {
from {opacity: 0;}
to {opacity: 1;}
}
<?php
$link = mysqli_connect ('localhost', 'root', 'mywebsite1245', 'CodersHome');
mysqli_select_db ($link, 'CodersHome');
//$con = mysqli_connect ('Localhost', 'id12806518_root', 'mywebsite1245', 'id12806518_codershome');
//mysqli_select_db ($con, 'id12806518_codershome');
?>
<?php
session_start ();
if( !isset($_SESSION['username']))
header('location:../login.php');
?>
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title>CodersHome Agenda</title>
<link rel="shortcut icon" type="image/png" href="../tabimg.png">
<meta name="viewport" content="width=device-width,initial-scale=1">
<link rel="stylesheet" href="profile/profile.css">
<link rel="stylesheet" type="text/css" href="../navbar/navbar.css">
<link rel="stylesheet" type="text/css" href="agendacss/agendap.css">
<link rel="stylesheet" type="text/css" href="agendacss/agendacard.css">
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.11.2/css/all.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/4.1.1/normalize.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script src="https://use.fontawesome.com/d1341f9b7a.js"></script>
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<script src="https://cdn.jsdelivr.net/npm/darkmode-js@1.5.5/lib/darkmode-js.min.js"></script>
<script src="https://cdn.ckeditor.com/4.14.0/standard/ckeditor.js"></script>
<script src="agendatabs.js" charset="utf-8"></script>
</head>
<?php include '../navbar/navbar.html' ?>
<body>
<div id="page-container">
<div id="content-wrap">
<ul class="tab">
<li><a href="#" class="tablinks active" onclick="openCity(event, 'agenda')"><strong>Agenda</strong></a></li>
<li><a href="#" class="tablinks" onclick="openCity(event, 'createagenda')"><strong>Crea Agenda</strong></a></li>
</ul>
<br>
<div id="agenda" class="tabcontent">
<div class="welcome">
<h1 class="weltitle">Agenda 1er D</h1>
</div>
<br><hr><br>
<?php
$result = mysqli_query($link,"SELECT * FROM agenda");
while($row = mysqli_fetch_array($result)) {
//echo $row["title"];
//echo $row["description"];
//echo $row["datef"];
?>
<?php $i=0; ?>
<div class="row">
<div class="column">
<div class="card">
<?php echo $row["description"]; ?>
<?php echo $row["datef"]; ?>                                                                                                                                                                                         <?php echo $row["inserter"]; ?> <?php if($_SESSION['username'] == 'admin') { include('eddel.php');
} ?> <br>
</div>
</div>
</div>
<br>
<?php
$i++;
}
?>
</div>
<div id="createagenda" class="tabcontent">
<div class="welcome2">
<p class="weltitle">Crea Una Agenda</p>
</div>
<br><hr><br>
<form class="agfrm" action="insert.php" method="post">
<div class="form-group">
<label>Title</label> <br> <br>
<input type="text" name="title" class="form-control" required><br> <br>
</div>
<div class="form-group">
<label>Description</label> <br> <br>
<textarea name="editor1" required></textarea>
<script>
CKEDITOR.replace( 'editor1' );
</script> <br> <br>
</div>
<label>Date</label> <br> <br>
<input type="date" id="date1" name="date1"
value="2020-02-25"
min="2020-01-01" max="2021-12-31" required> <br>
<br>
<button type="submit" class="homepbtn1">Sumbit</button>
</form>
</div>
</div>
</body>
</html>
<?php include '../Footer/index.html'?>