Так что для моего назначения мне нужно использовать имя пользователя вошедшего в систему пользователя и поместить его в другую таблицу в той же базе данных, когда указанный пользователь загружает изображение, и всякий раз, когда я пытаюсь загрузить, база данных появляетсятолько с идентификатором, остальное пусто.
Сценарий обработки:
<?php
if(isset($_POST['username'])) $username = $_POST['username'];
if(isset($_POST['title'])) $title = $_POST['title'];
if(isset($_POST['category'])) $category = $_POST['category'];
if(isset($_POST['description'])) $description = $_POST['description'];
if(isset($_POST['tags'])) $tags = $_POST['tags'];
$filename = $_FILES['image']['name'];
$location = $_FILES['image']['tmp_name'];
move_uploaded_file($location, "uploads/$filename");
$db = mysqli_connect("localhost", "root","", "artworks") or die(mysqli_error($db));
$q = "insert into artwork values(null, '$username', '$title', '$category', '$description', '$tags', '$filename')";
mysqli_query($db, $q) or die(mysqli_error($db));
header("Location:index.php");
exit(0); ?>
Сценарий входа в систему:
<?php
if(isset($_POST['username'])) $username = $_POST['username'];
if(isset($_POST['password'])) $password = $_POST['password'];
$db = mysqli_connect("localhost", "root","", "artworks") or die(mysqli_error($db));
$q = "select * from member where username='$username' and password=SHA('$password')";
$results = mysqli_query($db, $q) or die(mysqli_error($db));
if(mysqli_num_rows($results) > 0)
{
session_start();
$_SESSION['username'] = $username;
header("Location:index.php");
exit(0);
}
header("Location:register.php");?>
Сценарий загрузки
<?php
session_start();
if(!isset($_SESSION['username']))
{
header("Location:login.php");
exit(0);
}
?>
<?php include("header.inc");
include("nav.inc"); ?>
<div class = "container">
<form role = "form-horizontal" method = "post" action = "add_ps.php" enctype="multipart/form-data">
<div>
<div class = "form-group">
<label for = "title" class="control-label col-xs-6">Title</label>
<input type = "text" class = "form-control" id = "title" placeholder = "Title of Image">
</div>
</div>
<div>
<div class = "form-group">
<label for = "category" class="control-label col-xs-6">Category</label>
<input type = "text" class = "form-control" id = "category" placeholder = "Category of Image">
</div>
</div>
<div>
<div class = "form-group">
<label for = "description" class="control-label col-xs-6">Description</label>
<textarea class="form-control" rows="5" id="description" placeholder = "Description of Image"></textarea>
</div>
</div>
<div>
<div class = "form-group">
<label for = "tags" class="control-label col-xs-6">Tags (Seperate with comma)</label>
<input type = "text" class = "form-control" id = "tag" placeholder = "Tag of Image">
</div>
</div>
<div class = "form-group">
<label for = "inputfile">File input</label>
<input type = "file" id = "uploads">
<p class = "help-block">Upload image here</p>
</div>
<div class = "form-group">
<div class="col-xs-2">
<button type = "submit" class = "btn btn-primary">Submit</button>
</div>
</div>
</form>
</div>
<?php include("footer.inc"); ?>
Надеюсь, что это поможет, я чувствую, что упускаю некоторые мелкие детали