I have an html form with five inputs, named title, dateposted, content, tags and submit. I want to store the inputs in variables in a php file, then post them to a mysql database. I'm using PHPstorm and when I hover over $_POST it says reference error: $_POST is not defined. How do I fix this reference error? Is that why it's not submitting to the database?
My html form:
<div class="section" id="home">
<form action="insert.php" method="post">
<fieldset>
<legend>Title</legend>
<input id="title" name="title" placeholder="Title" type="text"/>
<input id="dateposted" type="text" placeholder="mm-dd-yyyy" name="dateposted"/>
</fieldset>
<fieldset>
<label>Content</label>
<textarea id="content" placeholder="content" name="content"> </textarea>
</fieldset>
<fieldset>
<label>Tags</label>
<input id="tags" type="text" placeholder="tags" name="tags"/>
</fieldset>
<fieldset>
<input id="submit" type="submit" value="Submit" name="Submit"/>
</fieldset>
</form>
</div>
PHP Code:
<?php
error_reporting(E_ALL);ini_set("display_error",true);
define('DB_NAME', 'blog_posts');
define('DB_USER', 'root');
define('DB_PASSWORD', '');
define('DB_HOST', 'localhost');
$link = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD);
if (!$link) {
die('Could not connect: ' . mysqli_error($link));
}
$db_selected = mysqli_select_db($link, DB_NAME);
if (!$db_selected) {
die('Can\'t use ' . DB_NAME . ': ' . mysqli_error($link));
}
//echo 'Connected successfully';
if(isset($_POST['Submit'])) {
$title = $_POST['title'];
$dateposted = $_POST['dateposted'];
$content = $_POST['content'];
$tags = $_POST['tags'];
$sqli = "INSERT INTO posts
("title", "dateposted", "content", "tags")
VALUES
('$title','$dateposted', '$content', '$tags')";
if (!mysqli_query($link, $sqli)) {
die('Error: ' . mysqli_error($link));
}
}
mysqli_close($link);