Reputation: 33
I have been working on this project for hours and need fresh eyes as to why the information from the forum is not being submitted into the database.
I have checked that the connection to the database was working. Whenever I try to submit an entry to the database, it shows that nothing goes wrong and goes to https://example.com/beta/index.php?post=success as it is supposed to but nothing except the auto_incremented id number
shows up into the database.
My form page:
if(!session_id()){
session_start();
}
require('loginregister-master/includes/config.php');
if ($_SESSION['username'] !== admin ) {
header("Location: https://www.example.com/beta");
}
//if not logged in redirect to login page
if(!$user->is_logged_in()){ header('Location: loginregister-master/login.php'); }
include('sec/HTTPS.php');
?>
<!DOCTYPE html>
<html>
<head>
<title>Post Blog</title>
<!-- Bootstrap Core CSS -->
<link href="vendor/bootstrap/css/bootstrap.min.css" rel="stylesheet">
<!-- Custom Fonts -->
<link href="vendor/font-awesome/css/font-awesome.min.css" rel="stylesheet" type="text/css">
<link href='https://fonts.googleapis.com/css?family=Lora:400,700,400italic,700italic' rel='stylesheet' type='text/css'>
<link href='https://fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,700italic,800italic,400,300,600,700,800' rel='stylesheet' type='text/css'>
<script src="vendor/jquery/jquery.min.js"></script>
</head>
<body>
<form action="likesdislike/post.php" method="POST">
<div class="form-group">
<label>Title</label>
<input type="title" class="form-control" name="title' placeholder="Title">
</div>
<div class="form-group">
<label>Content</label>
<input type="content" class="form-control" name="content' placeholder="Content">
</div>
<div class="form-group">
<label>Date</label>
<input type="text" class="form-control" name="etad' placeholder="Date">
</div>
<div class="form-group">
<label>Author</label>
<input type="text" class="form-control" name="author' placeholder="author">
</div>
<div class="form-group">
<label>URL</label>
<input type="text" class="form-control" name="URL' placeholder="URL">
</div>
<button type="submit" name="submit">Submit</button>
</form>
</body>
</html>
The bit that 'should' handle the submission the database:
<?php
include('connect.php');
$title = mysqli_real_escape_string($link, $_POST['title']);
$content = mysqli_real_escape_string($link, $_POST['content']);
$etad = mysqli_real_escape_string($link, $_POST['etad']);
$author = mysqli_real_escape_string($link, $_POST['author']);
$URL = mysqli_real_escape_string($link, $_POST['URL']);
$sql = "INSERT INTO posts (title, content, etad, author, URL) VALUES ('" . $title . "', '" . $content . "', '" . $etad . "', '" . $author . "', '" . $URL . "')";
mysqli_query($link, $sql);
header("Location: https://www.example.com/beta/index.php?post=success");
?>
And of course, the bit that handles the connection to the database:
<?php
$link = mysqli_connect("localhost", "username", "password", "database_name");
if($link === false){
die("ERROR: Could not connect. " . mysqli_connect_error());
}
?>
Upvotes: 1
Views: 47
Reputation: 1578
You have misplaced "
in name of html tags. Just do it with ""
.
<form action="likesdislike/post.php" method="POST">
<div class="form-group">
<label>Title</label>
<input type="title" class="form-control" name="title" placeholder="Title">
</div>
<div class="form-group">
<label>Content</label>
<input type="content" class="form-control" name="content" placeholder="Content">
</div>
<div class="form-group">
<label>Date</label>
<input type="text" class="form-control" name="etad" placeholder="Date">
</div>
<div class="form-group">
<label>Author</label>
<input type="text" class="form-control" name="author" placeholder="author">
</div>
<div class="form-group">
<label>URL</label>
<input type="text" class="form-control" name="URL" placeholder="URL">
</div>
<button type="submit" name="submit">Submit</button>
</form>
Upvotes: 1