Page 1 of 3

selectin data from the database with a session

Posted: Sun May 27, 2007 10:24 am
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'";

}

Posted: Sun May 27, 2007 11:50 am
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.

Posted: Sun May 27, 2007 12:02 pm
by franknu
SESSION:Array
(
[User_Name] => $User_Name
[Password] => $Password
)

Posted: Sun May 27, 2007 12:30 pm
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?

Posted: Sun May 27, 2007 12:42 pm
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

Posted: Sun May 27, 2007 1:00 pm
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

Posted: Sun May 27, 2007 1:10 pm
by volka
remove the quotes.

Posted: Sun May 27, 2007 1:15 pm
by franknu
i did and this is what i am getting now

Posted: Sun May 27, 2007 1:20 pm
by volka
:?:

Posted: Sun May 27, 2007 1:22 pm
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

Posted: Sun May 27, 2007 1:28 pm
by volka
$User_Name and $Password are supposed to be form parameters?
Then use $_POST['User_Name'] and $_POST['Password'] instead.

Posted: Sun May 27, 2007 1:31 pm
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'";
}

Posted: Sun May 27, 2007 3:00 pm
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'];
?>

Posted: Sun May 27, 2007 3:21 pm
by franknu
this is my display now

here

missing POST parameter User_Name or Password

Posted: Sun May 27, 2007 3:26 pm
by volka
Then you have to explain the supposed origin of $User_name and $Password.