Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- if(!isset($_POST['username'], $_POST['title'], $_POST['content'])) {
- header('Location: new-post.html');
- exit();
- }
- $servername = "localhost";
- $username = "hackeruser";
- $password = "Aa123456";
- $dbname = "reuven1";
- //create connection
- $conn = new mysqli($servername, $username, $password, $dbname);
- // Check connection
- if ($conn->connect_error) {
- die("connection failed: " . $conn->connect_error);
- }
- $sql = "INSERT INTO posts (username, title, content) VALUES ('".$_POST['username']."', '".$_POST['title']."', '".$_POST['content']."')";
- if ($conn->query($sql) === TRUE) {
- echo "New record created successfully";
- } else {
- echo "Error: ".$sql."<br>".$conn->error;
- }
- $conn->close();
- // Eventually redirect to index
- header('Location: index.php');
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement