/    Sign up×
Community /Pin to ProfileBookmark

how value session variable in database

Hello,

I have a login system, with the session show I the name of the member in the browser, if they log in.
I have have written a script that: When you logged in and signup for a event that the name of the member insert into a database. So the member then no need to enter the name in a form, you see the name in the session variable.
But this doesn’t work.
I get the error: Notice: Undefined index: username in C:xampphtdocsvrplatformsignup_event.php on line 26

my question is: How get I the name of the $_session[‘username’] into the database?

thanks in advance.

my code is:

[code=php] if ($_SESSION[‘username’]) echo “<p>welcome, ” .$_SESSION [‘username’] .” <a href=’logout.php’ onclick=’return confirm(“You want to log out?”)’>uitloggen</a></p>”;
else
header(“Location: index.php”);

$name = $_POST[‘username’];//this is line 26
$event = $_POST[‘signupn’];

//sql voor invoegen
$sql = “INSERT INTO connecttablel (name, name_event) VALUES ($name, $event)”;[/code]

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@NogDogMar 02.2016 — Do you do a (successful) session_start() on that page before you try to access the $_SESSION array? And, of course, you should do some defensive coding in case a user gets there without first logging in, or their login expires, e.g.:
[code=php]
<?php
ini_set('display_errors', true); // set to false in production
error_reporting(E_ALL);

session_start();

// any other code, then...
if(!empty($_SESSION['usernamej']) { // I recommend you always use braces for clarity
echo "your echo stuff here";
}
else {
header('Location: index.php'); // really should use a full URL
}
[/code]
×

Success!

Help @wesley5 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.3,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...