I'm trying to update date in database but for some reason it won't work, here is the code.
This is me PHP page where I put code to display data and I have an EDIT button that sends me to a page_edit where I cane type another NAME and UpdatE it. I want to pick a random row and edit name in it.
Main page (main.php)
<?php
if ($mysqli->connect_error) {die("Connection failed: " . $mysqli->connect_error);}
$sql = "SELECT * FROM users ORDER BY name";
$result = $mysqli->query($sql);
while ($rows = mysqli_fetch_array($result)) {
echo '
<div class="admin-content-con">
<header class="clearfix">
</header>
<table class="table table-striped">
<thead>
<tr>
<th>No</th>
<th>Name</th>
<th>Link</th>
<th>Actions</th>
</tr>
</thead>
<tbody>';
echo "<tr>";
echo "<td>" .$rows ['id']."</td>";
echo "<td>" .$rows ['name']."</td>";
echo "<td>" .$rows ['link']."</td>";
echo "<td>
<a href='page_edit.php?id=".$rows["id"]."'class='btn btn-xs btn-warning ' role='button'>edit</a>
<a href='delete.php?id=".$rows["id"]."'class='btn btn-xs btn-danger' role='button' onclick='return checkDelete()'>del</a></td>";
echo "</tr>";
echo '</tbody>
</table>
</div>';
}
?>
Page (page_edit.php).
<div class="settings-row">
<h3>Name</h3>
<p>This is permanently show on the left corner of navigation</p>
<form action="name.php" method="post" >
<div class="form-group">
<input type="text" class="form-control" name="name">
<input type="submit" value="Submit" name="submit">
</div>
</form>
</div>
PHP back-end code who update the database (name.php).
<?php
include '*';
$dbname = "*";
$conn = mysqli_connect("localhost", "root", "root", $dbname);
if (!$conn) { die("Connection failed: " . mysqli_connect_error()); }
$sql ="UPDATE users SET name='".$_POST['name']."' WHERE id='$id'";
if (mysqli_query($conn, $sql)) {
mysqli_close($conn);
header('Location: main.php');
exit;
} else {
echo "Error update record";
}
?>