How to I use all user info in sessions
How do I use things like $email and $image in sessions when I only use username and password to log ind. It seems like I only can use $username ()
I don't know how to collect the last user info to sessions?
server.php
<?php
session_start();
// variable declaration
$username = "";
$email = "";
$errors = array();
$_SESSION['success'] = "";
// connect to database
$db = mysqli_connect('Localhost', 'user', 'pass', 'db');
// REGISTER USER
if (isset($_POST['reg_user'])) {
// receive all input values from the form
$username = mysqli_real_escape_string($db, $_POST['username']);
$email = mysqli_real_escape_string($db, $_POST['email']);
$password_1 = mysqli_real_escape_string($db, $_POST['password_1']);
$password_2 = mysqli_real_escape_string($db, $_POST['password_2']);
$uploaddir = 'assets/images/users/';
$image = $uploaddir . basename($_FILES['userfile']['name']);
move_uploaded_file($_FILES['userfile']['tmp_name'], $image);
index.php
<?php
session_start();
if (!isset($_SESSION['username'])) {
$_SESSION['msg'] = "You must log in first";
header('location: pages-login.php');
}
if (isset($_GET['logout'])) {
session_destroy();
unset($_SESSION['username']);
header("location: pages-login.php");
}
?>
...
<?php if (isset($_SESSION['success'])) : ?>
<div class="success" >
<h3>
<?php
echo $_SESSION['success'];
unset($_SESSION['success']);
?>
</h3>
</div>
<?php endif ?>
<ol class="breadcrumb">
<li class="breadcrumb-item active">
<!-- logged in user information -->
<?php if (isset($_SESSION['username'])) : ?>
<p>Hej <strong><?php echo $_SESSION['username']; ?>! </strong>Velkommen til Kommandocentralen</p>
<?php endif ?>
<?php echo $_SESSION['email']; ?>!
</li>
</ol>
I can not get it to give $email the same way it gives me $username.
I cut out a lot of the code between the php-bits
php session
|
show 16 more comments
How do I use things like $email and $image in sessions when I only use username and password to log ind. It seems like I only can use $username ()
I don't know how to collect the last user info to sessions?
server.php
<?php
session_start();
// variable declaration
$username = "";
$email = "";
$errors = array();
$_SESSION['success'] = "";
// connect to database
$db = mysqli_connect('Localhost', 'user', 'pass', 'db');
// REGISTER USER
if (isset($_POST['reg_user'])) {
// receive all input values from the form
$username = mysqli_real_escape_string($db, $_POST['username']);
$email = mysqli_real_escape_string($db, $_POST['email']);
$password_1 = mysqli_real_escape_string($db, $_POST['password_1']);
$password_2 = mysqli_real_escape_string($db, $_POST['password_2']);
$uploaddir = 'assets/images/users/';
$image = $uploaddir . basename($_FILES['userfile']['name']);
move_uploaded_file($_FILES['userfile']['tmp_name'], $image);
index.php
<?php
session_start();
if (!isset($_SESSION['username'])) {
$_SESSION['msg'] = "You must log in first";
header('location: pages-login.php');
}
if (isset($_GET['logout'])) {
session_destroy();
unset($_SESSION['username']);
header("location: pages-login.php");
}
?>
...
<?php if (isset($_SESSION['success'])) : ?>
<div class="success" >
<h3>
<?php
echo $_SESSION['success'];
unset($_SESSION['success']);
?>
</h3>
</div>
<?php endif ?>
<ol class="breadcrumb">
<li class="breadcrumb-item active">
<!-- logged in user information -->
<?php if (isset($_SESSION['username'])) : ?>
<p>Hej <strong><?php echo $_SESSION['username']; ?>! </strong>Velkommen til Kommandocentralen</p>
<?php endif ?>
<?php echo $_SESSION['email']; ?>!
</li>
</ol>
I can not get it to give $email the same way it gives me $username.
I cut out a lot of the code between the php-bits
php session
I don't fully understand your question. Could you explain a bit because from what you explained,$email
,$image
and$username
are all variables, so why did you create them?
– Omari Celestine
Nov 18 '18 at 14:28
I get the variables from a registre form, and when I want to use them I can only use $username. if (isset($_POST['reg_user'])) { // receive all input values from form $username = mysqli_real_escape_string($db, $_POST['username']); $email = mysqli_real_escape_string($db, $_POST['email']); $password_1 = mysqli_real_escape_string($db, $_POST['password_1']); $password_2 = mysqli_real_escape_string($db, $_POST['password_2']); $uploaddir = 'assets/images/users/'; $image = $uploaddir . basename($_FILES['userfile']['name']); move_uploaded_file($_FILES['userfile']['tmp_name'], $image);
– Rue
Nov 18 '18 at 14:49
Could your update your question with the results of the output from the codeprint_r($_POST)
.
– Omari Celestine
Nov 18 '18 at 15:04
Have I done like you mean?
– Rue
Nov 18 '18 at 15:30
1
I'm sorry - as you can see I'm new to php. But you I want use the data when the user is logged in. I want to show profile image and write things like welcome back, $username - your email is $email.
– Rue
Nov 18 '18 at 19:38
|
show 16 more comments
How do I use things like $email and $image in sessions when I only use username and password to log ind. It seems like I only can use $username ()
I don't know how to collect the last user info to sessions?
server.php
<?php
session_start();
// variable declaration
$username = "";
$email = "";
$errors = array();
$_SESSION['success'] = "";
// connect to database
$db = mysqli_connect('Localhost', 'user', 'pass', 'db');
// REGISTER USER
if (isset($_POST['reg_user'])) {
// receive all input values from the form
$username = mysqli_real_escape_string($db, $_POST['username']);
$email = mysqli_real_escape_string($db, $_POST['email']);
$password_1 = mysqli_real_escape_string($db, $_POST['password_1']);
$password_2 = mysqli_real_escape_string($db, $_POST['password_2']);
$uploaddir = 'assets/images/users/';
$image = $uploaddir . basename($_FILES['userfile']['name']);
move_uploaded_file($_FILES['userfile']['tmp_name'], $image);
index.php
<?php
session_start();
if (!isset($_SESSION['username'])) {
$_SESSION['msg'] = "You must log in first";
header('location: pages-login.php');
}
if (isset($_GET['logout'])) {
session_destroy();
unset($_SESSION['username']);
header("location: pages-login.php");
}
?>
...
<?php if (isset($_SESSION['success'])) : ?>
<div class="success" >
<h3>
<?php
echo $_SESSION['success'];
unset($_SESSION['success']);
?>
</h3>
</div>
<?php endif ?>
<ol class="breadcrumb">
<li class="breadcrumb-item active">
<!-- logged in user information -->
<?php if (isset($_SESSION['username'])) : ?>
<p>Hej <strong><?php echo $_SESSION['username']; ?>! </strong>Velkommen til Kommandocentralen</p>
<?php endif ?>
<?php echo $_SESSION['email']; ?>!
</li>
</ol>
I can not get it to give $email the same way it gives me $username.
I cut out a lot of the code between the php-bits
php session
How do I use things like $email and $image in sessions when I only use username and password to log ind. It seems like I only can use $username ()
I don't know how to collect the last user info to sessions?
server.php
<?php
session_start();
// variable declaration
$username = "";
$email = "";
$errors = array();
$_SESSION['success'] = "";
// connect to database
$db = mysqli_connect('Localhost', 'user', 'pass', 'db');
// REGISTER USER
if (isset($_POST['reg_user'])) {
// receive all input values from the form
$username = mysqli_real_escape_string($db, $_POST['username']);
$email = mysqli_real_escape_string($db, $_POST['email']);
$password_1 = mysqli_real_escape_string($db, $_POST['password_1']);
$password_2 = mysqli_real_escape_string($db, $_POST['password_2']);
$uploaddir = 'assets/images/users/';
$image = $uploaddir . basename($_FILES['userfile']['name']);
move_uploaded_file($_FILES['userfile']['tmp_name'], $image);
index.php
<?php
session_start();
if (!isset($_SESSION['username'])) {
$_SESSION['msg'] = "You must log in first";
header('location: pages-login.php');
}
if (isset($_GET['logout'])) {
session_destroy();
unset($_SESSION['username']);
header("location: pages-login.php");
}
?>
...
<?php if (isset($_SESSION['success'])) : ?>
<div class="success" >
<h3>
<?php
echo $_SESSION['success'];
unset($_SESSION['success']);
?>
</h3>
</div>
<?php endif ?>
<ol class="breadcrumb">
<li class="breadcrumb-item active">
<!-- logged in user information -->
<?php if (isset($_SESSION['username'])) : ?>
<p>Hej <strong><?php echo $_SESSION['username']; ?>! </strong>Velkommen til Kommandocentralen</p>
<?php endif ?>
<?php echo $_SESSION['email']; ?>!
</li>
</ol>
I can not get it to give $email the same way it gives me $username.
I cut out a lot of the code between the php-bits
php session
php session
edited Nov 18 '18 at 15:54
Rue
asked Nov 18 '18 at 14:17
RueRue
185
185
I don't fully understand your question. Could you explain a bit because from what you explained,$email
,$image
and$username
are all variables, so why did you create them?
– Omari Celestine
Nov 18 '18 at 14:28
I get the variables from a registre form, and when I want to use them I can only use $username. if (isset($_POST['reg_user'])) { // receive all input values from form $username = mysqli_real_escape_string($db, $_POST['username']); $email = mysqli_real_escape_string($db, $_POST['email']); $password_1 = mysqli_real_escape_string($db, $_POST['password_1']); $password_2 = mysqli_real_escape_string($db, $_POST['password_2']); $uploaddir = 'assets/images/users/'; $image = $uploaddir . basename($_FILES['userfile']['name']); move_uploaded_file($_FILES['userfile']['tmp_name'], $image);
– Rue
Nov 18 '18 at 14:49
Could your update your question with the results of the output from the codeprint_r($_POST)
.
– Omari Celestine
Nov 18 '18 at 15:04
Have I done like you mean?
– Rue
Nov 18 '18 at 15:30
1
I'm sorry - as you can see I'm new to php. But you I want use the data when the user is logged in. I want to show profile image and write things like welcome back, $username - your email is $email.
– Rue
Nov 18 '18 at 19:38
|
show 16 more comments
I don't fully understand your question. Could you explain a bit because from what you explained,$email
,$image
and$username
are all variables, so why did you create them?
– Omari Celestine
Nov 18 '18 at 14:28
I get the variables from a registre form, and when I want to use them I can only use $username. if (isset($_POST['reg_user'])) { // receive all input values from form $username = mysqli_real_escape_string($db, $_POST['username']); $email = mysqli_real_escape_string($db, $_POST['email']); $password_1 = mysqli_real_escape_string($db, $_POST['password_1']); $password_2 = mysqli_real_escape_string($db, $_POST['password_2']); $uploaddir = 'assets/images/users/'; $image = $uploaddir . basename($_FILES['userfile']['name']); move_uploaded_file($_FILES['userfile']['tmp_name'], $image);
– Rue
Nov 18 '18 at 14:49
Could your update your question with the results of the output from the codeprint_r($_POST)
.
– Omari Celestine
Nov 18 '18 at 15:04
Have I done like you mean?
– Rue
Nov 18 '18 at 15:30
1
I'm sorry - as you can see I'm new to php. But you I want use the data when the user is logged in. I want to show profile image and write things like welcome back, $username - your email is $email.
– Rue
Nov 18 '18 at 19:38
I don't fully understand your question. Could you explain a bit because from what you explained,
$email
, $image
and $username
are all variables, so why did you create them?– Omari Celestine
Nov 18 '18 at 14:28
I don't fully understand your question. Could you explain a bit because from what you explained,
$email
, $image
and $username
are all variables, so why did you create them?– Omari Celestine
Nov 18 '18 at 14:28
I get the variables from a registre form, and when I want to use them I can only use $username. if (isset($_POST['reg_user'])) { // receive all input values from form $username = mysqli_real_escape_string($db, $_POST['username']); $email = mysqli_real_escape_string($db, $_POST['email']); $password_1 = mysqli_real_escape_string($db, $_POST['password_1']); $password_2 = mysqli_real_escape_string($db, $_POST['password_2']); $uploaddir = 'assets/images/users/'; $image = $uploaddir . basename($_FILES['userfile']['name']); move_uploaded_file($_FILES['userfile']['tmp_name'], $image);
– Rue
Nov 18 '18 at 14:49
I get the variables from a registre form, and when I want to use them I can only use $username. if (isset($_POST['reg_user'])) { // receive all input values from form $username = mysqli_real_escape_string($db, $_POST['username']); $email = mysqli_real_escape_string($db, $_POST['email']); $password_1 = mysqli_real_escape_string($db, $_POST['password_1']); $password_2 = mysqli_real_escape_string($db, $_POST['password_2']); $uploaddir = 'assets/images/users/'; $image = $uploaddir . basename($_FILES['userfile']['name']); move_uploaded_file($_FILES['userfile']['tmp_name'], $image);
– Rue
Nov 18 '18 at 14:49
Could your update your question with the results of the output from the code
print_r($_POST)
.– Omari Celestine
Nov 18 '18 at 15:04
Could your update your question with the results of the output from the code
print_r($_POST)
.– Omari Celestine
Nov 18 '18 at 15:04
Have I done like you mean?
– Rue
Nov 18 '18 at 15:30
Have I done like you mean?
– Rue
Nov 18 '18 at 15:30
1
1
I'm sorry - as you can see I'm new to php. But you I want use the data when the user is logged in. I want to show profile image and write things like welcome back, $username - your email is $email.
– Rue
Nov 18 '18 at 19:38
I'm sorry - as you can see I'm new to php. But you I want use the data when the user is logged in. I want to show profile image and write things like welcome back, $username - your email is $email.
– Rue
Nov 18 '18 at 19:38
|
show 16 more comments
2 Answers
2
active
oldest
votes
Following the same guidlines of the tutorial, on the server.php
page, when the user registers or login, after the line that says $_SESSION['username'] = $username;
, you can add other session data after that as follows:
When registering the user:
// REGISTER USER
if (isset($_POST['reg_user'])) {
...
$_SESSION['username'] = $username;
$_SESSION['email'] = $email;
...
}
When the user logs in:
// LOGIN USER
if (isset($_POST['login_user'])) {
...
$row = $results->fetch_array();
$_SESSION['username'] = $username;
$_SESSION['email'] = $row['email'];
...
}
For the user login, $results[0]['email']
, references the email
column of your database table so whichever data you want to make available, will need to use the same as is in the tabla. For example you would reference the image
column as $results[0]['image']
.
All other session variables can be set following the above pattern.
Hope this helps.
It doesn't. I still doesn't work. I can't get email to show in the index.php. And I got an error because of: $_SESSION['email'] = $results[0]['email'];
– Rue
Nov 19 '18 at 11:32
@Rue, Sorry I forgot part of the code. Check the answer now and let me know.
– Omari Celestine
Nov 19 '18 at 11:44
Yes! it worked :) thanks!
– Rue
Nov 19 '18 at 11:50
Can you tell me how my image column I my database should look for it to save my images? $uploaddir = 'assets/images/users/'; $image = $uploaddir . basename($_FILES['userfile']['name']); move_uploaded_file($_FILES['userfile']['tmp_name'], $image);
– Rue
Nov 19 '18 at 12:06
@Rue What you would do is create a column of type VARCHAR(255) or TEXT which would store the name of the image file. So you could have for example,$image_name = basename($_FILES['userfile']['name']
, and you would store that value in the database. Did that answer your question?
– Omari Celestine
Nov 19 '18 at 12:24
add a comment |
yes it worked - it stored the image in the folder I requested. but now I'm not sure how to show it?
// REGISTER USER
...
$uploaddir = 'assets/images/users/';
$image = $uploaddir . basename($_FILES['userfile']['name']);
move_uploaded_file($_FILES['userfile']['tmp_name'], $image);
...
$_SESSION['username'] = $username;
$_SESSION['email'] = $email;
$_SESSION['userfile'] = $image;
...
// LOGIN USER
...
$row = $results->fetch_array();
...
$_SESSION['username'] = $username;
$_SESSION['email'] = $row['email'];
$_SESSION['userfile'] = $row['userfile'];
...
And then in the index.php
...
<img src="<?php echo $_SESSION['userfile']; ?>" />
...
But nothing shows - can you se what my error is?
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53361858%2fhow-to-i-use-all-user-info-in-sessions%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Following the same guidlines of the tutorial, on the server.php
page, when the user registers or login, after the line that says $_SESSION['username'] = $username;
, you can add other session data after that as follows:
When registering the user:
// REGISTER USER
if (isset($_POST['reg_user'])) {
...
$_SESSION['username'] = $username;
$_SESSION['email'] = $email;
...
}
When the user logs in:
// LOGIN USER
if (isset($_POST['login_user'])) {
...
$row = $results->fetch_array();
$_SESSION['username'] = $username;
$_SESSION['email'] = $row['email'];
...
}
For the user login, $results[0]['email']
, references the email
column of your database table so whichever data you want to make available, will need to use the same as is in the tabla. For example you would reference the image
column as $results[0]['image']
.
All other session variables can be set following the above pattern.
Hope this helps.
It doesn't. I still doesn't work. I can't get email to show in the index.php. And I got an error because of: $_SESSION['email'] = $results[0]['email'];
– Rue
Nov 19 '18 at 11:32
@Rue, Sorry I forgot part of the code. Check the answer now and let me know.
– Omari Celestine
Nov 19 '18 at 11:44
Yes! it worked :) thanks!
– Rue
Nov 19 '18 at 11:50
Can you tell me how my image column I my database should look for it to save my images? $uploaddir = 'assets/images/users/'; $image = $uploaddir . basename($_FILES['userfile']['name']); move_uploaded_file($_FILES['userfile']['tmp_name'], $image);
– Rue
Nov 19 '18 at 12:06
@Rue What you would do is create a column of type VARCHAR(255) or TEXT which would store the name of the image file. So you could have for example,$image_name = basename($_FILES['userfile']['name']
, and you would store that value in the database. Did that answer your question?
– Omari Celestine
Nov 19 '18 at 12:24
add a comment |
Following the same guidlines of the tutorial, on the server.php
page, when the user registers or login, after the line that says $_SESSION['username'] = $username;
, you can add other session data after that as follows:
When registering the user:
// REGISTER USER
if (isset($_POST['reg_user'])) {
...
$_SESSION['username'] = $username;
$_SESSION['email'] = $email;
...
}
When the user logs in:
// LOGIN USER
if (isset($_POST['login_user'])) {
...
$row = $results->fetch_array();
$_SESSION['username'] = $username;
$_SESSION['email'] = $row['email'];
...
}
For the user login, $results[0]['email']
, references the email
column of your database table so whichever data you want to make available, will need to use the same as is in the tabla. For example you would reference the image
column as $results[0]['image']
.
All other session variables can be set following the above pattern.
Hope this helps.
It doesn't. I still doesn't work. I can't get email to show in the index.php. And I got an error because of: $_SESSION['email'] = $results[0]['email'];
– Rue
Nov 19 '18 at 11:32
@Rue, Sorry I forgot part of the code. Check the answer now and let me know.
– Omari Celestine
Nov 19 '18 at 11:44
Yes! it worked :) thanks!
– Rue
Nov 19 '18 at 11:50
Can you tell me how my image column I my database should look for it to save my images? $uploaddir = 'assets/images/users/'; $image = $uploaddir . basename($_FILES['userfile']['name']); move_uploaded_file($_FILES['userfile']['tmp_name'], $image);
– Rue
Nov 19 '18 at 12:06
@Rue What you would do is create a column of type VARCHAR(255) or TEXT which would store the name of the image file. So you could have for example,$image_name = basename($_FILES['userfile']['name']
, and you would store that value in the database. Did that answer your question?
– Omari Celestine
Nov 19 '18 at 12:24
add a comment |
Following the same guidlines of the tutorial, on the server.php
page, when the user registers or login, after the line that says $_SESSION['username'] = $username;
, you can add other session data after that as follows:
When registering the user:
// REGISTER USER
if (isset($_POST['reg_user'])) {
...
$_SESSION['username'] = $username;
$_SESSION['email'] = $email;
...
}
When the user logs in:
// LOGIN USER
if (isset($_POST['login_user'])) {
...
$row = $results->fetch_array();
$_SESSION['username'] = $username;
$_SESSION['email'] = $row['email'];
...
}
For the user login, $results[0]['email']
, references the email
column of your database table so whichever data you want to make available, will need to use the same as is in the tabla. For example you would reference the image
column as $results[0]['image']
.
All other session variables can be set following the above pattern.
Hope this helps.
Following the same guidlines of the tutorial, on the server.php
page, when the user registers or login, after the line that says $_SESSION['username'] = $username;
, you can add other session data after that as follows:
When registering the user:
// REGISTER USER
if (isset($_POST['reg_user'])) {
...
$_SESSION['username'] = $username;
$_SESSION['email'] = $email;
...
}
When the user logs in:
// LOGIN USER
if (isset($_POST['login_user'])) {
...
$row = $results->fetch_array();
$_SESSION['username'] = $username;
$_SESSION['email'] = $row['email'];
...
}
For the user login, $results[0]['email']
, references the email
column of your database table so whichever data you want to make available, will need to use the same as is in the tabla. For example you would reference the image
column as $results[0]['image']
.
All other session variables can be set following the above pattern.
Hope this helps.
edited Nov 19 '18 at 11:43
answered Nov 19 '18 at 11:20
Omari CelestineOmari Celestine
422211
422211
It doesn't. I still doesn't work. I can't get email to show in the index.php. And I got an error because of: $_SESSION['email'] = $results[0]['email'];
– Rue
Nov 19 '18 at 11:32
@Rue, Sorry I forgot part of the code. Check the answer now and let me know.
– Omari Celestine
Nov 19 '18 at 11:44
Yes! it worked :) thanks!
– Rue
Nov 19 '18 at 11:50
Can you tell me how my image column I my database should look for it to save my images? $uploaddir = 'assets/images/users/'; $image = $uploaddir . basename($_FILES['userfile']['name']); move_uploaded_file($_FILES['userfile']['tmp_name'], $image);
– Rue
Nov 19 '18 at 12:06
@Rue What you would do is create a column of type VARCHAR(255) or TEXT which would store the name of the image file. So you could have for example,$image_name = basename($_FILES['userfile']['name']
, and you would store that value in the database. Did that answer your question?
– Omari Celestine
Nov 19 '18 at 12:24
add a comment |
It doesn't. I still doesn't work. I can't get email to show in the index.php. And I got an error because of: $_SESSION['email'] = $results[0]['email'];
– Rue
Nov 19 '18 at 11:32
@Rue, Sorry I forgot part of the code. Check the answer now and let me know.
– Omari Celestine
Nov 19 '18 at 11:44
Yes! it worked :) thanks!
– Rue
Nov 19 '18 at 11:50
Can you tell me how my image column I my database should look for it to save my images? $uploaddir = 'assets/images/users/'; $image = $uploaddir . basename($_FILES['userfile']['name']); move_uploaded_file($_FILES['userfile']['tmp_name'], $image);
– Rue
Nov 19 '18 at 12:06
@Rue What you would do is create a column of type VARCHAR(255) or TEXT which would store the name of the image file. So you could have for example,$image_name = basename($_FILES['userfile']['name']
, and you would store that value in the database. Did that answer your question?
– Omari Celestine
Nov 19 '18 at 12:24
It doesn't. I still doesn't work. I can't get email to show in the index.php. And I got an error because of: $_SESSION['email'] = $results[0]['email'];
– Rue
Nov 19 '18 at 11:32
It doesn't. I still doesn't work. I can't get email to show in the index.php. And I got an error because of: $_SESSION['email'] = $results[0]['email'];
– Rue
Nov 19 '18 at 11:32
@Rue, Sorry I forgot part of the code. Check the answer now and let me know.
– Omari Celestine
Nov 19 '18 at 11:44
@Rue, Sorry I forgot part of the code. Check the answer now and let me know.
– Omari Celestine
Nov 19 '18 at 11:44
Yes! it worked :) thanks!
– Rue
Nov 19 '18 at 11:50
Yes! it worked :) thanks!
– Rue
Nov 19 '18 at 11:50
Can you tell me how my image column I my database should look for it to save my images? $uploaddir = 'assets/images/users/'; $image = $uploaddir . basename($_FILES['userfile']['name']); move_uploaded_file($_FILES['userfile']['tmp_name'], $image);
– Rue
Nov 19 '18 at 12:06
Can you tell me how my image column I my database should look for it to save my images? $uploaddir = 'assets/images/users/'; $image = $uploaddir . basename($_FILES['userfile']['name']); move_uploaded_file($_FILES['userfile']['tmp_name'], $image);
– Rue
Nov 19 '18 at 12:06
@Rue What you would do is create a column of type VARCHAR(255) or TEXT which would store the name of the image file. So you could have for example,
$image_name = basename($_FILES['userfile']['name']
, and you would store that value in the database. Did that answer your question?– Omari Celestine
Nov 19 '18 at 12:24
@Rue What you would do is create a column of type VARCHAR(255) or TEXT which would store the name of the image file. So you could have for example,
$image_name = basename($_FILES['userfile']['name']
, and you would store that value in the database. Did that answer your question?– Omari Celestine
Nov 19 '18 at 12:24
add a comment |
yes it worked - it stored the image in the folder I requested. but now I'm not sure how to show it?
// REGISTER USER
...
$uploaddir = 'assets/images/users/';
$image = $uploaddir . basename($_FILES['userfile']['name']);
move_uploaded_file($_FILES['userfile']['tmp_name'], $image);
...
$_SESSION['username'] = $username;
$_SESSION['email'] = $email;
$_SESSION['userfile'] = $image;
...
// LOGIN USER
...
$row = $results->fetch_array();
...
$_SESSION['username'] = $username;
$_SESSION['email'] = $row['email'];
$_SESSION['userfile'] = $row['userfile'];
...
And then in the index.php
...
<img src="<?php echo $_SESSION['userfile']; ?>" />
...
But nothing shows - can you se what my error is?
add a comment |
yes it worked - it stored the image in the folder I requested. but now I'm not sure how to show it?
// REGISTER USER
...
$uploaddir = 'assets/images/users/';
$image = $uploaddir . basename($_FILES['userfile']['name']);
move_uploaded_file($_FILES['userfile']['tmp_name'], $image);
...
$_SESSION['username'] = $username;
$_SESSION['email'] = $email;
$_SESSION['userfile'] = $image;
...
// LOGIN USER
...
$row = $results->fetch_array();
...
$_SESSION['username'] = $username;
$_SESSION['email'] = $row['email'];
$_SESSION['userfile'] = $row['userfile'];
...
And then in the index.php
...
<img src="<?php echo $_SESSION['userfile']; ?>" />
...
But nothing shows - can you se what my error is?
add a comment |
yes it worked - it stored the image in the folder I requested. but now I'm not sure how to show it?
// REGISTER USER
...
$uploaddir = 'assets/images/users/';
$image = $uploaddir . basename($_FILES['userfile']['name']);
move_uploaded_file($_FILES['userfile']['tmp_name'], $image);
...
$_SESSION['username'] = $username;
$_SESSION['email'] = $email;
$_SESSION['userfile'] = $image;
...
// LOGIN USER
...
$row = $results->fetch_array();
...
$_SESSION['username'] = $username;
$_SESSION['email'] = $row['email'];
$_SESSION['userfile'] = $row['userfile'];
...
And then in the index.php
...
<img src="<?php echo $_SESSION['userfile']; ?>" />
...
But nothing shows - can you se what my error is?
yes it worked - it stored the image in the folder I requested. but now I'm not sure how to show it?
// REGISTER USER
...
$uploaddir = 'assets/images/users/';
$image = $uploaddir . basename($_FILES['userfile']['name']);
move_uploaded_file($_FILES['userfile']['tmp_name'], $image);
...
$_SESSION['username'] = $username;
$_SESSION['email'] = $email;
$_SESSION['userfile'] = $image;
...
// LOGIN USER
...
$row = $results->fetch_array();
...
$_SESSION['username'] = $username;
$_SESSION['email'] = $row['email'];
$_SESSION['userfile'] = $row['userfile'];
...
And then in the index.php
...
<img src="<?php echo $_SESSION['userfile']; ?>" />
...
But nothing shows - can you se what my error is?
answered Nov 19 '18 at 12:58
RueRue
185
185
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53361858%2fhow-to-i-use-all-user-info-in-sessions%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
I don't fully understand your question. Could you explain a bit because from what you explained,
$email
,$image
and$username
are all variables, so why did you create them?– Omari Celestine
Nov 18 '18 at 14:28
I get the variables from a registre form, and when I want to use them I can only use $username. if (isset($_POST['reg_user'])) { // receive all input values from form $username = mysqli_real_escape_string($db, $_POST['username']); $email = mysqli_real_escape_string($db, $_POST['email']); $password_1 = mysqli_real_escape_string($db, $_POST['password_1']); $password_2 = mysqli_real_escape_string($db, $_POST['password_2']); $uploaddir = 'assets/images/users/'; $image = $uploaddir . basename($_FILES['userfile']['name']); move_uploaded_file($_FILES['userfile']['tmp_name'], $image);
– Rue
Nov 18 '18 at 14:49
Could your update your question with the results of the output from the code
print_r($_POST)
.– Omari Celestine
Nov 18 '18 at 15:04
Have I done like you mean?
– Rue
Nov 18 '18 at 15:30
1
I'm sorry - as you can see I'm new to php. But you I want use the data when the user is logged in. I want to show profile image and write things like welcome back, $username - your email is $email.
– Rue
Nov 18 '18 at 19:38