How to I use all user info in sessions
up vote
2
down vote
favorite
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
up vote
2
down vote
favorite
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 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 at 14:49
Could your update your question with the results of the output from the codeprint_r($_POST)
.
– Omari Celestine
Nov 18 at 15:04
Have I done like you mean?
– Rue
Nov 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 at 19:38
|
show 16 more comments
up vote
2
down vote
favorite
up vote
2
down vote
favorite
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 at 15:54
asked Nov 18 at 14:17
Rue
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 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 at 14:49
Could your update your question with the results of the output from the codeprint_r($_POST)
.
– Omari Celestine
Nov 18 at 15:04
Have I done like you mean?
– Rue
Nov 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 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 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 at 14:49
Could your update your question with the results of the output from the codeprint_r($_POST)
.
– Omari Celestine
Nov 18 at 15:04
Have I done like you mean?
– Rue
Nov 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 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 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 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 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 at 14:49
Could your update your question with the results of the output from the code
print_r($_POST)
.– Omari Celestine
Nov 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 at 15:04
Have I done like you mean?
– Rue
Nov 18 at 15:30
Have I done like you mean?
– Rue
Nov 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 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 at 19:38
|
show 16 more comments
2 Answers
2
active
oldest
votes
up vote
1
down vote
accepted
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 at 11:32
@Rue, Sorry I forgot part of the code. Check the answer now and let me know.
– Omari Celestine
Nov 19 at 11:44
Yes! it worked :) thanks!
– Rue
Nov 19 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 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 at 12:24
add a comment |
up vote
0
down vote
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 |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
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 at 11:32
@Rue, Sorry I forgot part of the code. Check the answer now and let me know.
– Omari Celestine
Nov 19 at 11:44
Yes! it worked :) thanks!
– Rue
Nov 19 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 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 at 12:24
add a comment |
up vote
1
down vote
accepted
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 at 11:32
@Rue, Sorry I forgot part of the code. Check the answer now and let me know.
– Omari Celestine
Nov 19 at 11:44
Yes! it worked :) thanks!
– Rue
Nov 19 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 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 at 12:24
add a comment |
up vote
1
down vote
accepted
up vote
1
down vote
accepted
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 at 11:43
answered Nov 19 at 11:20
Omari Celestine
392211
392211
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 at 11:32
@Rue, Sorry I forgot part of the code. Check the answer now and let me know.
– Omari Celestine
Nov 19 at 11:44
Yes! it worked :) thanks!
– Rue
Nov 19 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 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 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 at 11:32
@Rue, Sorry I forgot part of the code. Check the answer now and let me know.
– Omari Celestine
Nov 19 at 11:44
Yes! it worked :) thanks!
– Rue
Nov 19 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 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 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 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 at 11:32
@Rue, Sorry I forgot part of the code. Check the answer now and let me know.
– Omari Celestine
Nov 19 at 11:44
@Rue, Sorry I forgot part of the code. Check the answer now and let me know.
– Omari Celestine
Nov 19 at 11:44
Yes! it worked :) thanks!
– Rue
Nov 19 at 11:50
Yes! it worked :) thanks!
– Rue
Nov 19 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 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 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 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 at 12:24
add a comment |
up vote
0
down vote
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 |
up vote
0
down vote
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 |
up vote
0
down vote
up vote
0
down vote
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 at 12:58
Rue
185
185
add a comment |
add a comment |
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 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 at 14:49
Could your update your question with the results of the output from the code
print_r($_POST)
.– Omari Celestine
Nov 18 at 15:04
Have I done like you mean?
– Rue
Nov 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 at 19:38