Hi this has been frustrating me for a while and I can't seem to figure out what is wrong with my code
So I currently have a database called artworks and it has 2 tables within it a artwork table and a members
table ( for login including username
and password
)
I already have login.php that stores username
and password
to the members
table
Now I want to get that username from members table and store it within artworks table somehow. ( I do not know why my code is not storing my username
into it)
<?php
session_start();
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 the file
move_uploaded_file($location, "uploads/$filename");
//put data into database
$db = mysqli_connect("localhost", "root","", "artworks") or die(mysqli_error($db));
$_SESSION['username'] = $username;
$q = "insert into artwork values(null, '$_SESSION[username]','$title', '$category', '$description', '$tags', '$filename')";
mysqli_query($db, $q) or die(mysqli_error($db));
//redirect
header("Location:gallery.php");
exit(0);
Ive also tried $_SESSION['username'] = $username;
and $_SESSION['username'] = '$username';
and it still does not seem to work
I also want to display the current logged in user's name at the bottom of the page but echo $username
also does not work ..
Many Thanks