Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions article-form.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php
//update-article.php
$connection = mysqli_connect('localhost','user','pass') or die ("Couldn't connect to server.");
$db = mysqli_select_db('cm_blog', $connection) or die ("Couldn't select database.");

$title=$_POST['titlefield'];
$body=$_POST['bodyfield'];

$data = "UPDATE `article` SET title='$Title', body='$Body' WHERE article_ID=".'"'.$Key.'"';
$query = mysqli_query($data) or die("Couldn't execute query. ". mysqli_error());

// header('Location: article-list.php');

?>

<!DOCTYPE HTML>
<!-- article-form.php -->
<html>
<head>
<title></title>

</head>

<body>

<form method="post" action="update-article.php>
<input type="text" name="name">
</form>
<!-- display the changed record from database -->
title: <?php echo $title?><br>
body: <?php echo $body?> <br>

</body>

</html>
27 changes: 27 additions & 0 deletions article-list.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "myDB";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}

$sql = "SELECT article_id, author_user_id, title, body, publish_date FROM cm_blog.article ORDER BY publish_date DESC";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
echo "<tr>";
echo "<td>" .$row['article_id']. "</td>"; echo "<td>" .$row['author_user_id']. "</td>"; echo "<td>" .$row['title']. "</td>"; echo "<td>" .$row['body']. "</td>"; echo "<td>" .$row['publish_date']. "</td>"; echo "</tr>";
}
} else {
echo "0 results";
}
$conn->close();
?>