franknu Posted May 27, 2007 Share Posted May 27, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/53127-sessions/ Share on other sites More sharing options...
dustinnoe Posted May 27, 2007 Share Posted May 27, 2007 <?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! Quote Link to comment https://forums.phpfreaks.com/topic/53127-sessions/#findComment-262437 Share on other sites More sharing options...
chronister Posted May 27, 2007 Share Posted May 27, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/53127-sessions/#findComment-262460 Share on other sites More sharing options...
franknu Posted May 27, 2007 Author Share Posted May 27, 2007 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'"; } Quote Link to comment https://forums.phpfreaks.com/topic/53127-sessions/#findComment-262675 Share on other sites More sharing options...
chocopi Posted May 27, 2007 Share Posted May 27, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/53127-sessions/#findComment-262678 Share on other sites More sharing options...
franknu Posted May 27, 2007 Author Share Posted May 27, 2007 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'"; } Quote Link to comment https://forums.phpfreaks.com/topic/53127-sessions/#findComment-262683 Share on other sites More sharing options...
chocopi Posted May 27, 2007 Share Posted May 27, 2007 Replace $query = "SELECT * FROM business_info where $User_Name='$User_Name' AND $Password = '$Password'"; With $query = "SELECT * FROM business_info where User_Name='$User_Name' AND Password = '$Password'"; Quote Link to comment https://forums.phpfreaks.com/topic/53127-sessions/#findComment-262688 Share on other sites More sharing options...
chronister Posted May 27, 2007 Share Posted May 27, 2007 <?php $host = "localhost"; $username = "fgyfhg"; $password = "jhghjg $database = "jgjhgfh"; ?> This may be a just be a typo posted here, but your missing a "; at the end of $password. If this is the case in your actual script, this would make the script end unexpectedly. Quote Link to comment https://forums.phpfreaks.com/topic/53127-sessions/#findComment-262704 Share on other sites More sharing options...
franknu Posted May 27, 2007 Author Share Posted May 27, 2007 I did this <pre>_SESSION:<?php print_r($_SESSION); ?></pre> my display SESSION:Array ( [user_Name] => $User_Name [Password] => $Password ) Quote Link to comment https://forums.phpfreaks.com/topic/53127-sessions/#findComment-262720 Share on other sites More sharing options...
franknu Posted May 27, 2007 Author Share Posted May 27, 2007 I guess my session is not working what am i doing wrong Quote Link to comment https://forums.phpfreaks.com/topic/53127-sessions/#findComment-262742 Share on other sites More sharing options...
franknu Posted May 27, 2007 Author Share Posted May 27, 2007 well maybe my session is na carrying User_Name AND Password Values into that page any idea on what i might be doing wrong and how i can fix it Quote Link to comment https://forums.phpfreaks.com/topic/53127-sessions/#findComment-262763 Share on other sites More sharing options...
chronister Posted May 27, 2007 Share Posted May 27, 2007 <?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. Quote Link to comment https://forums.phpfreaks.com/topic/53127-sessions/#findComment-262766 Share on other sites More sharing options...
franknu Posted May 27, 2007 Author Share Posted May 27, 2007 i did and this is what i am gettin now _SESSION:Array ( [user_Name] => [Password] => ) Quote Link to comment https://forums.phpfreaks.com/topic/53127-sessions/#findComment-262778 Share on other sites More sharing options...
chocopi Posted May 27, 2007 Share Posted May 27, 2007 Is that before or after you ran the form because if it is before then there is no way that they will have a value as you will have set nothing to them. Quote Link to comment https://forums.phpfreaks.com/topic/53127-sessions/#findComment-262781 Share on other sites More sharing options...
franknu Posted May 27, 2007 Author Share Posted May 27, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/53127-sessions/#findComment-262784 Share on other sites More sharing options...
franknu Posted May 27, 2007 Author Share Posted May 27, 2007 please help, i am totally lost here Quote Link to comment https://forums.phpfreaks.com/topic/53127-sessions/#findComment-262800 Share on other sites More sharing options...
chronister Posted May 27, 2007 Share Posted May 27, 2007 _SESSION:Array ( [user_Name] => [Password] => ) What is the top part? The _SESSION part is missing a $ Post your code again so we can see what you have . Quote Link to comment https://forums.phpfreaks.com/topic/53127-sessions/#findComment-262801 Share on other sites More sharing options...
franknu Posted May 28, 2007 Author Share Posted May 28, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/53127-sessions/#findComment-262941 Share on other sites More sharing options...
chronister Posted May 28, 2007 Share Posted May 28, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/53127-sessions/#findComment-262982 Share on other sites More sharing options...
franknu Posted May 28, 2007 Author Share Posted May 28, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/53127-sessions/#findComment-263014 Share on other sites More sharing options...
chronister Posted May 28, 2007 Share Posted May 28, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/53127-sessions/#findComment-263017 Share on other sites More sharing options...
franknu Posted May 28, 2007 Author Share Posted May 28, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/53127-sessions/#findComment-263019 Share on other sites More sharing options...
chronister Posted May 28, 2007 Share Posted May 28, 2007 <?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> Quote Link to comment https://forums.phpfreaks.com/topic/53127-sessions/#findComment-263021 Share on other sites More sharing options...
franknu Posted May 28, 2007 Author Share Posted May 28, 2007 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']}\"> "; ?> Quote Link to comment https://forums.phpfreaks.com/topic/53127-sessions/#findComment-263031 Share on other sites More sharing options...
chronister Posted May 28, 2007 Share Posted May 28, 2007 If this line is not giving you the variables you expect, then your session is not populating correctly. <pre>_SESSION:<?php print_r($_SESSION); ?></pre> Make sure that your calling session_start() on your first page above anything else. Before the <html> tag even. Quote Link to comment https://forums.phpfreaks.com/topic/53127-sessions/#findComment-263046 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.