selectin data from the database with a session

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

franknu
Forum Contributor
Posts: 146
Joined: Sun May 28, 2006 9:29 am

selectin data from the database with a session

Post by franknu »

Ok my problem is that it is not selecting from database , maybe i am using session the wrong way i am a newbie

here is my code

starting my session

Code: Select all

<?
session_start();
$_SESSION['User_Name'] = '$User_Name';
$_SESSION['Password'] = '$Password';

?>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<?php

$host     = "localhost";
$username = "fgyfhg";
$password = "jhghjg
$database = "jgjhgfh";

$db = mysql_connect($host, $username, $password) or die(mysql_error());
mysql_select_db($database) or die(mysql_error());



$BusinessName = (isset($_POST['BusinessName']) ? $_POST['BusinessName'] : '');
$Slogan = (isset($_POST['Slogan']) ? $_POST['Slogan']:'');
this is how i am calling it

Code: Select all

if ( isset($_SESSION['User_Name']) && isset($_SESSION['Password']) ) {

$username=$_SESSION['User_Name'];
$password=$_SESSION['Password'];

$query = "SELECT * FROM business_info where $username='$User_Name' AND $password = '$Password'";

}
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

please try

Code: Select all

<?
session_start();
$_SESSION['User_Name'] = '$User_Name';
$_SESSION['Password'] = '$Password';

?>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<pre>_SESSION:<?php print_r($_SESSION); ?></pre>
<?php 
...
and take a look at the output.
franknu
Forum Contributor
Posts: 146
Joined: Sun May 28, 2006 9:29 am

Post by franknu »

SESSION:Array
(
[User_Name] => $User_Name
[Password] => $Password
)
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

And that's not what you want, is it? ;)
$_SESSION['User_Name'] = '$User_Name';
$_SESSION['Password'] = '$Password';
Why are there single-quotes? Actually Why are there quotes at all?
franknu
Forum Contributor
Posts: 146
Joined: Sun May 28, 2006 9:29 am

Post by franknu »

Well, i dont know about the quotes that is what i saw everywhere there was a session samples

but actualli what i want is the session to grab the user name and password from the database or

it should be user Franklin password franklin01
franknu
Forum Contributor
Posts: 146
Joined: Sun May 28, 2006 9:29 am

Post by franknu »

well maybe my session is not carrying User_Name AND Password Values into that page

any idea on what i might be doing wrong and how i can fix it
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

remove the quotes.
franknu
Forum Contributor
Posts: 146
Joined: Sun May 28, 2006 9:29 am

Post by franknu »

i did and this is what i am getting now
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

:?:
franknu
Forum Contributor
Posts: 146
Joined: Sun May 28, 2006 9:29 am

Post by franknu »

_SESSION:Array
(
[User_Name] =>
[Password] =>
)


this is at the bottom of the page:


Warning: Unknown(): Your script possibly relies on a session side-effect which existed until PHP 4.2.3. Please be advised that the session extension does not consider global variables as a source of data, unless register_globals is enabled. You can disable this functionality and this warning by setting session.bug_compat_42 or session.bug_compat_warn to off, respectively. in Unknown on line 0
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

$User_Name and $Password are supposed to be form parameters?
Then use $_POST['User_Name'] and $_POST['Password'] instead.
franknu
Forum Contributor
Posts: 146
Joined: Sun May 28, 2006 9:29 am

Post by franknu »

how do i use it here this is my code



and this is what i have a the top of th page

<?php

session_start();

$_SESSION['User_Name'] = $User_Name;
$_SESSION['Password'] = $Password;
?>





if ( isset($_SESSION['User_Name']) && isset($_SESSION['Password']) ) {


$query = "SELECT * FROM business_info where User_Name='$User_Name' AND Password = '$Password'";
}
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

Code: Select all

<?php
if ( !isset($_POST['User_Name'], $_POST['Password']) ) {
	die('missing POST parameter User_Name or Password');
}
session_start();
$_SESSION['User_Name'] = $_POST['User_Name'];
$_SESSION['Password'] = $_POST['Password'];
?>
franknu
Forum Contributor
Posts: 146
Joined: Sun May 28, 2006 9:29 am

Post by franknu »

this is my display now

here

missing POST parameter User_Name or Password
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

Then you have to explain the supposed origin of $User_name and $Password.
Post Reply