I have a code here that won't update. If I input anything inside the input texts and press submit, the 'samp.php' will still display the original information of the database that I have updated.
codes for index.php
<?php
include 'connect.php';
?>
<html>
<head>
<title>Basic Form Handling PHP</title>
</head>
<body>
<?php
$result1 = $db->query("select * from chapter where chapter_id='1'");
while($row1 = mysqli_fetch_assoc($result1)){ echo "<form action='samp.php' method='POST'>";
echo " <input class='input' type='hidden' name='cid' value='{$row1['chapter_id']}'/>";
echo " Title: <br>";
echo " <input type='text' name='ctitle'><br>";
echo " Body: <br>";
echo " <input type='text' name='cbody'><br>";
echo " <input type='submit' name='submit' value='PRESS ME'>";
echo " </form>";
}
?>
</body>
</html>
codes for connect.php
<?php
$db = new mysqli('localhost', 'root', '2830775', 'unity');
?>
codes for samp.php
<?php
include 'connect.php';
?>
<?php
$id = $_POST['cid'];
$title = $_POST['ctitle'];
$body = $_POST['cbody'];
$result = $db->query("UPDATE chapter set chapter_title='$title', chapter_body='$body' where chapter_id='$id");
$result2 = $db->query("SELECT * FROM chapter where chapter_id='$id'");
?>
<?php $row1 = mysqli_fetch_assoc($result2);
echo $row1['chapter_body'];
?>
Update $result = $db->query("UPDATE chapter set chapter_title='$title', chapter_body='$body' where chapter_id='$id")
to $result = $db->query("UPDATE chapter set chapter_title='$title', chapter_body='$body' where chapter_id='$id'")
You forgot to end single quote there.
You need to include your connection file to your same.php
<?php
include 'connect.php';// incliude your connection file
$id = $_POST['cid'];
$title = $_POST['ctitle'];
$body = $_POST['cbody'];
$result = $db->query("UPDATE chapter set chapter_title='$title', chapter_body='$body' where chapter_id = '$id'");//missing Singal quote in end
$result2 = $db->query("SELECT * FROM chapter where chapter_id='$id'");
?>
<?php
$row1 = mysqli_fetch_assoc($result2);
echo $row1['chapter_body'];
?>