Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within PHP
Search Coderanch
Advance search
Google search
Register / Login
Win a copy of
Microservices Testing (Live Project)
this week in the
Spring
forum!
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Tim Cooke
Ron McLeod
Jeanne Boyarsky
Paul Clapham
Sheriffs:
Liutauras Vilda
Henry Wong
Devaka Cooray
Saloon Keepers:
Tim Moores
Stephan van Hulst
Tim Holloway
Al Hobbs
Carey Brown
Bartenders:
Piet Souris
Mikalai Zaikin
Himai Minh
Forum:
PHP
session variable problem
muntago Richard
Ranch Hand
Posts: 82
posted 9 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
This code does not display a simple.php page if correct account were entered. i think there is a session login problem
<?php session_start(); $_SESSION['userid']; $_SESSION['username']; ?> <body> Welcoome user $_SESSION['username']; <h2>Current User Session</h2> <?=$_SESSION['username']?> (ID = <?=$_SESSION['userid']?> ) </body> </html>
<?php session_start(); $host="localhost"; // Host name $username="root"; // Mysql username $password=""; // Mysql password $db_name="timeline"; // Database name $tbl_name="users"; // Table name // Connect to server and select databse. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); // username and password sent from form $username=$_POST['username']; $password=$_POST['password']; // To protect MySQL injection (more detail about MySQL injection) $username = stripslashes($username); $password = stripslashes($password); $username = mysql_real_escape_string($username); $password = mysql_real_escape_string($password); $sql="SELECT * FROM $tbl_name WHERE username='$username' and password='$password'"; $result=mysql_query($sql); // Mysql_num_row is counting table row $count=mysql_num_rows($result); // If result matched $myusername and $mypassword, table row must be 1 row if($count==1){ $member = mysql_fetch_assoc($result); $_SESSION['userid']; $_SESSION['user_name']; header("location: simple.php"); } else { echo "Wrong Username or Password"; } ?>
ibrahim yener
Ranch Hand
Posts: 202
I like...
posted 9 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
There is no session problem. Simply you are not assigning value to Session variables.
Look at your code
if($count==1){ $member = mysql_fetch_assoc($result); $_SESSION['userid']; $_SESSION['user_name']; header("location: simple.php"); }
should be
if($count==1){ $member = mysql_fetch_assoc($result); $_SESSION['userid'] = $member['user_id']; $_SESSION['user_name'] = $member['user_name']; header("location: simple.php"); }
My Google play account
shivdhwaj pandey
Ranch Hand
Posts: 67
I like...
posted 8 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
You are creating session but not assigning the value to session variable that`s the problem.
And place exit; just after the header();
with regards,
Shivdhway Pandey
Anindya Roy
Ranch Hand
Posts: 76
posted 8 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
mysql_* functions have been deprecated instead please use mysqli_* or PDO
Thanks
With a little knowledge, a
cast iron skillet
is non-stick and lasts a lifetime.
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
i need help on loggin account limit
php database addition problem
Java Applet Logon Post to PHP
difficulty in login in one attempt
undefined variable
More...