Hi!
So I managed to upload the picture via php to a folder BUT my problem now is that I want to INSERT the location path of the uploaded picture to the user's pic_location in the database and I don't know how the query will look if I want to achieve that.
The member is logged in when he uploads the pic so the SESSION is running.
I will give you my code to have a look see and if you can spot what to do...
Thanks
My picUpload.php (Where I uploaded the picture and where I want to INSERT the location path into the user's pic_loaction column in the table users)
<?php
include 'connect.php';
include 'header.php';
//This is the directory where images will be saved
$target=$_SERVER['DOCUMENT_ROOT'] . "/images/" . basename( $_FILES['file']['name']);
//This gets all the other information from the form
$pic_location=($_FILES['file']['name']);
//Writes the information to the database
$sql = "INSERT INTO users (pic_location) VALUES ('$pic_location')" ;
//Writes the photo to the server
if(move_uploaded_file($_FILES['file']['tmp_name'], $target))
{
//Tells you if its all ok
echo "The file ". basename( $_FILES['file']['name']). " has been uploaded, and your information has been added to the directory";
}
else {
//Gives and error if its not
echo "Sorry, there was a problem uploading your file.";
}
///////////////////////////////
////////// HELP HERE //////////
///////////////////////////////
//Putting the storage path in the logged in user's pic_location path
//HOW WILL THE QUERY LOOK IF I WANT TO ADD THE PATH OF THE UPLOADED PICTURE TO THE USER'S pic_location IN THE DATABASE TABLE???
$sql = "INSERT INTO
users(pic_location)
VALUES('" . mysql_real_escape_string($_POST['pic_location']) . "',NOW(),0)";
$result = mysql_query($sql);
if(!$result)
{
//something went wrong, display the error
echo 'Error!';
}
else
{
echo 'Success!';
}
?>
my profile.php
<?php
include 'connect.php';
include 'header.php';
if(isset($_SESSION['signed_in']) == false || isset($_SESSION['user_level']) != 1 )
{
//the user is not an admin
echo '<br/>';
echo 'Sorry! You have to be <a href="/signin.php"><b>logged in</b></a> to view your profile <a href="signup.php" title="Become a registered user!"></a>.';
echo '<br/><br/>';
}
else
{
echo '<h2>Profile of </h2>'.$_SESSION['user_name'];
echo '<h2>Info about you: </h2>';
echo '<img src="beetgejo.jpg"/>'; echo'<pp><a href="#" title="Change your profile picture">edit</a></pp>';
echo '<br/><br/>';
echo '<b>Logged in as: </b>'.$_SESSION['user_name']; echo'<pp><a href="#" title="Change your user name">edit</a></pp>';
echo '<br/><br/>';
echo '<b>Your email address: </b>'.$_SESSION['user_email']; echo'<pp><a href="#" title="Change your email address">edit</a></pp>';
echo '<br/><br/>';
echo '<b>Your user level: </b>'.$_SESSION['user_level'].' (1 = admin AND 0 = user)';
echo '<br/><br/>';
echo '<b>Your friends: </b> // FRIENDS';
//echo 'Welcome, ' . $_SESSION['user_name'] . '! <br /><br/><br/><a href="index.php"><b>Proceed to the link sharing</b></a>.';
///////////////////////////////
/// adding users as friends ///
///////////////////////////////
//while($user = mysql_fetch_array($result))
//echo $user['user_name'].'
//<a href="addfriend.php?user='.$user['id'].'">ADD TO FRIENDS</a><br/>';
echo 'Do you want to upload or change your profile picture?';
echo '<br/><br/>';
echo '<form action="picUpload.php" method="post" enctype="multipart/form-data">
<label for="file">Filename: </label>
<input type="file" name="file" id="file"/>
<br/>
<input type="submit" name="submit" value="Upload" />
</form>';
//NOW I WANT TO MAKE A SPECIFIC "ADD AS FRIEND" LINK NEXT TO EACH USER
}
include 'footer.php';
?>
and my database.sql
CREATE TABLE users (
user_id INT(8) NOT NULL AUTO_INCREMENT,
user_name VARCHAR(30) NOT NULL,
user_pass VARCHAR(255) NOT NULL,
user_email VARCHAR(255) NOT NULL,
user_date DATETIME NOT NULL,
user_level INT(8) NOT NULL,
pic_location VARCHAR(255) NOT NULL,
UNIQUE INDEX user_name_unique (user_name),
PRIMARY KEY (user_id)
);
CREATE TABLE categories (
cat_id INT(8) NOT NULL AUTO_INCREMENT,
cat_name VARCHAR(255) NOT NULL,
cat_description VARCHAR(255) NOT NULL,
UNIQUE INDEX cat_name_unique (cat_name),
PRIMARY KEY (cat_id)
);
CREATE TABLE topics (
topic_id INT(8) NOT NULL AUTO_INCREMENT,
topic_subject VARCHAR(255) NOT NULL,
topic_date DATETIME NOT NULL,
topic_cat INT(8) NOT NULL,
topic_by INT(8) NOT NULL,
PRIMARY KEY (topic_id)
);
CREATE TABLE posts (
post_id INT(8) NOT NULL AUTO_INCREMENT,
post_content TEXT NOT NULL,
post_date DATETIME NOT NULL,
post_topic INT(8) NOT NULL,
post_by INT(8) NOT NULL,
PRIMARY KEY (post_id)
);