Created
April 6, 2013 08:45
-
-
Save isstaif/5325438 to your computer and use it in GitHub Desktop.
Simple website using PHP and MySQL
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<form action='newpost.php' method=post> | |
Title: <input type=text name=title /> | |
Body: <input type=text name=body /> | |
<input type=submit /> | |
</form> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$con = mysqli_connect('localhost', 'root', '', 'db'); | |
$query = "INSERT INTO posts (id, title, body) VALUES (NULL, '".$_POST['title']."', '". $_POST['body'] . "');"; | |
$result = mysqli_query($con, $query); | |
echo "Thank you!"; | |
header("location:posts.php"); | |
?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head></head> | |
<body> | |
<?php | |
$con = mysqli_connect('localhost', 'root', '', 'db'); | |
$id= $_GET['id']; | |
$query = "SELECT * FROM `posts` WHERE id=". $id; | |
$result = mysqli_query($con, $query); | |
$post = mysqli_fetch_assoc($result); | |
echo "<h1>".$post['title']."</h1>"; | |
echo "<p>".$post['body']."</p>"; | |
echo "<hr />"; | |
?> | |
<a href='posts.php'>Back</a> | |
</body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head></head> | |
<body> | |
<a href='new.html'>Create a new post!</a> | |
<?php | |
$con = mysqli_connect('localhost', 'root', '', 'db'); | |
$result = mysqli_query($con, "SELECT * FROM `posts`"); | |
while ($post = mysqli_fetch_assoc($result)){ | |
$link = "<a href='post.php?id=".$post['id']. "'>"; | |
echo $link; | |
echo "<h1>".$post['title']."</h1>"; | |
echo "</a>"; | |
echo "<p>".$post['body']."</p>"; | |
echo "<hr />"; | |
} | |
?> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment