Jump to content

Recommended Posts

Ok, i am new to this session thing what is the right way to do this

 


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


$query = "SELECT * FROM business_info where $_SESSION['User_Name']='$User_Name' AND $_SESSION['Password'] = '$Password'";


}

 

what is the right way to do this any idea

i am gettin a parser error in the query line here is the error

 

Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in

Link to comment
https://forums.phpfreaks.com/topic/53127-sessions/
Share on other sites

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


$query = "SELECT * FROM business_info WHERE {$_SESSION['User_Name']}='{$User_Name}' AND {$_SESSION['Password']} = '{$Password}'";


}
?>

 

Using curly braces forces PHP to interpret the variables.  Hope that helps!

Link to comment
https://forums.phpfreaks.com/topic/53127-sessions/#findComment-262437
Share on other sites

Or you can break out of the quotes like this....

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


$query = "SELECT * FROM business_info where ". $_SESSION['User_Name'] ."='$User_Name' AND ". $_SESSION['Password']." = '$Password'";


}
?>

 

Or even better...

<?php

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'";

}
?>

 

Although, why is your username and password field names in the query being set with variables?

 

Shouldn't the query be something like this?

 

<?php

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

?>

 

Your query should basically read,

 

select all from TABLENAME where FIELD1=$variable AND FIELD2=$variable

 

 

Link to comment
https://forums.phpfreaks.com/topic/53127-sessions/#findComment-262460
Share on other sites

Ok my only problem now is that it is not selecting from database

 

here is my code

 

starting my session

 


<?
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

 


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'";

}

Link to comment
https://forums.phpfreaks.com/topic/53127-sessions/#findComment-262675
Share on other sites

surely as chronister said it would need to be:

 

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

 

This is assuming your column names are username and password

 

Instead of:

 

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

 

Your current code is saying that the column name is $username and the other is $password, meaning you have a new colum for every user and password.

 

Hope that helps,

 

~ Chocopi

Link to comment
https://forums.phpfreaks.com/topic/53127-sessions/#findComment-262678
Share on other sites

My colums Name are User_Name AND Password here there are some changes i made with not result


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

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

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

}

 

Link to comment
https://forums.phpfreaks.com/topic/53127-sessions/#findComment-262683
Share on other sites

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

 

remove the ' ' from the $User_Name & $Password.

 

WHen you use ' ' around a variable, your making it a literal string, not a variable.

 

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

 

That should work for you.

Link to comment
https://forums.phpfreaks.com/topic/53127-sessions/#findComment-262766
Share on other sites

that is after, i am olso gettin this message that i didnt see 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

Link to comment
https://forums.phpfreaks.com/topic/53127-sessions/#findComment-262784
Share on other sites

Ok i added that i also added the

 

 

<pre>_SESSION:<?php print_r($_SESSION); ?></pre> into the member page

 

and this is my display

 

SESSION:Array

(

[user_Name] => franklin

[Password] => franklin01

)

 

so the problem looks like it is not carrien the User_Name and Password into the next page

 

so please help

Link to comment
https://forums.phpfreaks.com/topic/53127-sessions/#findComment-262941
Share on other sites

One mistake almost everyone makes when working with sessions is that they forget to call session_start() at the top of each page they are using sessions on.

 

This shows that the sessions are being filled with values

 

Array
(
[user_Name] => franklin
[Password] => franklin01
) 

 

If you cannot retreive those on the second page by using $_SESSION['User_Name'] & $_SESSION['Password'] then you must not be calling the session_start() on the second page.

 

So you should be good to go by doing this...

 

 

<?php

session_start();

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


echo $username;
echo '<br>';
echo $password;

?>

 

Place this on another page or even a blank page and see if it echo's the values that are being set.

 

 

Link to comment
https://forums.phpfreaks.com/topic/53127-sessions/#findComment-262982
Share on other sites

hey i created another page and here is my

 

display

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/townsfin/public_html/authorization/test2.php:11) in /home/townsfin/public_html/authorization/test2.php on line 13

 

then on my other page he one what i am working on

 

this

session_start(); 
$username=$_SESSION['User_Name'];
$password=$_SESSION['Password'];


echo' $username';
echo '<br>';
echo '$password';

 

produce this:

$username

$password

Link to comment
https://forums.phpfreaks.com/topic/53127-sessions/#findComment-263014
Share on other sites

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/townsfin/public_html/authorization/test2.php:11) in /home/townsfin/public_html/authorization/test2.php on line 13

 

output started at /home/townsfin/public_html/authorization/test2.php:11

 

Look to Line 11, you are echoing out something before you are calling start_session();

 

 

session_start(); 
$username=$_SESSION['User_Name'];
$password=$_SESSION['Password'];


echo' $username';
echo '<br>';
echo '$password';

 

YOU CANNOT PUT ' ' AROUND VARIABLES. I have already said this. It turns your variable into a literal string.

 

It must be

echo $username;
echo '<br>';
echo $password;

 

 

Post all your code for test2.php

Link to comment
https://forums.phpfreaks.com/topic/53127-sessions/#findComment-263017
Share on other sites

the reason why i addes the quotes was because before that i was not displaying anything

 

there is the whole code for test2

 


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<?php

session_start();

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


echo $username;
echo '<br>';
echo $password;

?>
</body>
</html>

 

thank for helpin

Link to comment
https://forums.phpfreaks.com/topic/53127-sessions/#findComment-263019
Share on other sites

<?php
//session start MUST be called before any thing else... even a blank line above the <?php will cause an errror
//
session_start();
$username=$_SESSION['User_Name'];
$password=$_SESSION['Password'];
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<?php
// if these don't show anything, the session is not being populated correctly
echo 'Username is '. $username;
echo '<br>';
echo 'Password is '.$password;
?>
</body>
</html>

Link to comment
https://forums.phpfreaks.com/topic/53127-sessions/#findComment-263021
Share on other sites

Ok i went remove space on the line at the top

 

for page1 is display user name and password but for page2 it doesnt

 

any peace of advise

 

here is partial part of  my code for page2

 


<?php 
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">
<style type="text/css">
<!--
.style1 {
color: #FFFFFF;
font-weight: bold;
}
-->
</style>
</head>

<body>
<?php
// this info is private but it has it 
$host     = "l";
$username = "";
$password = "";
$database = "";

$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']:'');
$Business_Address = (isset($_POST['Business_Address']) ? $_POST['Business_Address']:'');
$Tel = (isset($_POST['Tel']) ? $_POST['Tel']:'');
$Website = (isset($_POST['Website']) ? $_POST['Website']:'');
$Email = (isset($_POST['Email']) ? $_POST['Email']:'');
$Member_Status = (isset($_POST['Member_Status']) ? $_POST['Member_Status']:'');
$Fax =(isset($_POST['Fax']) ? $_POST['Fax']:'');
$type = (isset($_POST['type']) ? $_POST['type']:'');
$make = (isset($_POST['make']) ? $_POST['make']:'');
$Categories = (isset($_POST['Categories']) ? $_POST['Categories']:'');
$Keyword = (isset($_POST['Keyword']) ? $_POST['Keyword']:'');
$Picture1 =  (isset($_POST['Picture1']) ? $_POST['Picture1']:'');
$Headline =  (isset($_POST['Headline']) ? $_POST['Headline']:'');
$Slogan2 = (isset($_POST['Slogan2']) ? $_POST['Slogan2']:'');
$Description1 = (isset($_POST['Description1']) ? $_POST['Description1']:'');
$Description2 = (isset($_POST['Description2']) ? $_POST['Description2']:'');
$Description3= (isset($_POST['Description3']) ? $_POST['Description3']:'');
$Contact2 = (isset($_POST['Contact2']) ? $_POST['Contact2']:'');
$Picture2 =  (isset($_POST['Picture2']) ? $_POST['Picture2']:'');
$Picture3 = (isset($_POST['Picture3']) ? $_POST['Picture3']:'');
$Picture4 =  (isset($_POST['Picture4']) ? $_POST['Picture4']:'');
$User_Name = (isset($_POST['User_Name']) ? $_POST['User_Name']:'');
$Password = (isset($_POST['Password']) ? $_POST['Password']: '');





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


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

?>



<table width="356" border="0">
  <tr>
    <td width="346"><table width="514" border="1">

<pre>_SESSION:<?php print_r($_SESSION); ?></pre> 

<?

// if these don't show anything, the session is not being populated correctly
echo 'Username is '. $username;
echo '<br>';
echo 'Password is '.$password;
?>

   ?>   <tr>
        <td width="504" background="fondo2.jpg"> </td>
      </tr>
      <tr>
        <td><table width="537" border="1" bordercolor="#E0DFE3" bgcolor="#CCCCCC">
          <tr> <?
	  echo'<form action="'. $_SERVER['PHP_SELF'].'" method="post" enctype="multipart/form-data">';
	  ?>
            <td width="67">Business Name </td>
            <td width="148">
		<?
		echo" 

		<input type=\"text\" name=\"BusinessName\" value=\"{$row['BusinessName']}\">  "; 
		?>

Link to comment
https://forums.phpfreaks.com/topic/53127-sessions/#findComment-263031
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.