Hi guys. working my way through a tutorial. i have a form with a text input, a select input, a file input and a textarea input. i think the problem is with the file input as when i select a file on the form page and hover over it after it doesnt show the file name like it does in the tutorial. whatever is happenning the data isnt going to the atabase table. would the dodgy file input prevent that? all the code is in the one page but ill break up the php from the html
[CODE]
<?php require_once(“includes/db.php”);?>
<?php require_once(“includes/functions.php”);?>
<?php require_once(“includes/sessions.php”);?>
<?php
ini_set(‘display_errors’, true); // set to false in production
error_reporting(E_ALL);
?>
<?php
if(isset($_POST[“submit”])){
$postTitle = $_POST[“postTitle”];
$category = $_POST[“category”];
$image = $_FILES[“image”][“name”];
$target = “uploads/”.basename($_FILES[“image”][“name”]);
$postDescription = $_POST[“postDescription”];
$admin = “cole”;
date_default_timezone_set(“Europe/Dublin”);
$currenttime = time();
$datetime= strftime(“%B-%d-%Y %H:%M:%S”, $currenttime);
if(empty($postTitle)){
$_SESSION[“error”] = “please add a post title”;
redirect(“addnewpost.php”);
}elseif(strlen($postTitle)<5){
$_SESSION[“error”] = “post title must be longer than 5 charachters”;
redirect(“addnewpost.php”);
}elseif(strlen($postDescription)>999){
$_SESSION[“error”] = “post must be less than 1000 charachters”;
redirect(“addnewpost.php”);
}else {
$sql = “INSERT INTO posts(datetime,title,category,author,image,post) VALUES(:entrytime,:postTitle,:postCategory,:adminName,:pic,:postText)”;
$stmt = $connect->prepare($sql);
$stmt->bindValue(‘:entrytime’,$datetime);
$stmt->bindValue(‘:postTitle’,$postTitle);
$stmt->bindValue(‘:postCategory’,$category);
$stmt->bindValue(‘:admiNname’,$admin);
$stmt->bindValue(‘:pic’,$image);
$stmt->bindValue(‘:postText’,$postDescription);
$Execute = $stmt->execute();
if($Execute){
$_SESSION[“success”] = “data added successfully”;
redirect(“addnewpost.php”);
}else {
$_SESSION[“error”] = “something went wrong. data not added to table”;
redirect(“addnewpost.php”);
}
}
}
?>
HTML
[CODE]
<!doctype html>
<html>
<head>
<meta charset=”utf-8″>
<meta name=”viewport” content=”width=device-width, initial-scale=1.0″>
<meta http-equiv=”X-UA-compatible” content=”ie=edge”>
<title>Add new post</title>
<link rel=”stylesheet” href=”https://use.fontawesome.com/releases/v5.7.2/css/all.css” integrity=”sha384-fnmOCqbTlWIlj8LyTjo7mOUStjsKC4pOpQbqyi7RrhN7udi9RwhKkMHpvLbHG9Sr” crossorigin=”anonymous”>
<link rel=”stylesheet” href=”https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css” integrity=”sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T” crossorigin=”anonymous”>
<link rel=”stylesheet” href=”css/styles.css”>
</head>
<body>
<!– NAVBAR START –>
<div style=”height:10px; background-color:rgb(100,100,100);”></div>
<nav class=”navbar navbar-expand-lg bg-dark navbar-dark”>
<div class=”container”>
<a href=”#” class=”navbar-brand”>jazebakram.com</a>
<button class=”navbar-toggler” data-toggle=”collapse” data-target=”#navbarcollapsecms”><span class=”navbar-toggler-icon”></span></button>
<div class=”collapse navbar-collapse” id=”navbarcollapsecms”>
<ul class=”navbar-nav mr-auto”>
<li class=”nav-item”><a href=”myprofile.php” class=”nav-link”> <i class=”fas fa-user”></i> Profile</a></li>
<li class=”nav-item”><a href=”dashboard.php” class=”nav-link”>Dashboard</a></li>
<li class=”nav-item”><a href=”posts.hp” class=”nav-link”>Posts</a></li>
<li class=”nav-item”><a href=”catagories.php” class=”nav-link”>Catagories</a></li>
<li class=”nav-item”><a href=”admins.php” class=”nav-link”>Manage admins</a></li>
<li class=”nav-item”><a href=”comments.php” class=”nav-link”>Comments</a></li>
<li class=”nav-item”><a href=”blog.php?page=1″ class=”nav-link”>Live blog</a></li>
</ul>
<ul class=”navbar-nav ml-auto”>
<li class=”nav-item”><a href=”logout.php” class=”nav-link”><i class=”fas fa-user-times”></i> Log out</a></li>
</ul>
</div>
</div>
</nav>
<div style=”height:10px; background-color:rgb(100,100,100);”></div>
<!– NAVBAR END –>
<!– HEADER START –>
<header class=”bg-dark text-white”>
<div class=”container”>
<div class=”row”>
<h1> <i class=”fas fa-edit style=”color: #27aae1;”></i> Manage posts</h1>
</div>
</div>
</header>
<!– HEADER END –>
<!– MAIN AREA –>
<section class=”container py-2 mb-4″>
<div class=”row”>
<div class=”offset-lg-1 col-lg-10″ style=”min-height: 600px;”>
<?php
echo errormessage();
echo successmessage();
?>
<form action=”addnewpost.php” method=”post” enctype=”multipart/form-data”>
<div class=”card bg-secondary text-light “>
</div>
<div class=”card-body bg-dark” >
<div class=”form-group”>
<label for=”postTitle”><span class=”fieldinfo”>post title:</span></label>
<input class=”form-control” type=”text” name=”postTitle” id=”postTitle”>
</div>
<div class=”form-group”>
<label for=”category title”><span class=”fieldinfo”>choose Category:</span></label>
<select class=”form-control” id=”categoryTitle” name=”category”>
<?php
global $connect;
$sql = “SELECT * FROM category”;
$stmt = $connect->query($sql);
while ($daterows = $stmt->fetch()){
$categoryname = $daterows[“title”];
echo “<option> $categoryname </option>”;
}
?>
?>
</select>
</div>
<div class=”form-group”>
<div class=”custom-file”>
<input type=”file” name=”image” id=”imageselect” value=””>
<label for=”imageselect”class=”custom-file-label”>Select image</label>
</div>
</div>
<div class=”form-group”>
<label for=”post”><span class=”fieldinfo”>Post:</span></label>
<textarea class=”form-control” id=”post” name=”postDescription” rows=”8″ cols=”80″></textarea>
</div>
<div class=”row”>
<div class=”col-lg-6 mb-2″>
<a href=”dashboard.php” class=”btn btn-warning btn-lg btn-block”><i class=”fas fa-arrow-left”>Back to dashboard</i></a>
</div>
<div class=”col-lg-6 mb-2″>
<button type=”submit” name=”submit” class=”btn btn-success btn-lg btn-block”><i class=”fas fa-check”>Publish</i></button>
</div>
</div>
</div>
</form>
</div>
</div>
</section>
<!– FOOTER START –>
<footer class=”bg-dark text-white”>
<div class-“container”>
<div class=”row”>
<div class=”col”>
<p class=”lead text-center”>Theme by Cole Pratt</p>
</div>
</div>
</div>
</footer>
<script src=”https://code.jquery.com/jquery-3.3.1.slim.min.js” integrity=”sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo” crossorigin=”anonymous”></script>
<script src=”https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js” integrity=”sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1″ crossorigin=”anonymous”></script>
<script src=”https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js” integrity=”sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM” crossorigin=”anonymous”></script>
</body>
</html>