By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,614 Members | 1,674 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,614 IT Pros & Developers. It's quick & easy.

Session Variables

P: 8
I've got this piece of script:
[php]
$schque = $_SESSION['user'];
$a=$_REQUEST['$schque'];
$username="daedalus_admin";
$password="test";
$database="daedalus_db";

mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query="SELECT * FROM user WHERE username='$a'";
$result=mysql_query($query);
$num=mysql_numrows($result);
[/php]
Read the Posting Guidelines at the top of this forum, especially the part about enclosing shown code within php or code tags!!!

moderator


The problem is that $schque is the correct value, but it won't pass to $a. I've tried put $schque straight into the query but that doesn't work either. Any help would be appriecated.
Mar 2 '07 #1
Share this Question
Share on Google+
7 Replies


ak1dnar
Expert 100+
P: 1,584
From your coding You are trying to Fetch the session Variable that you have already created some where(a page) in your Application.

But to Get that session variable to this page first you have to Add

[PHP]
<?
session_start();
//Then Your Coding.....
?>
[/PHP]
Mar 2 '07 #2

P: 8
From your coding You are trying to Fetch the session Variable that you have already created some where(a page) in your Application.

But to Get that session variable to this page first you have to Add

[PHP]
<?
session_start();
//Then Your Coding.....
?>
[/PHP]
I've got that further up, sorry should have posted it as well.

It won't take the variable from $schque and put it into $a
Mar 2 '07 #3

ak1dnar
Expert 100+
P: 1,584
Try This Sample

First.php
[PHP]<?php
session_start();// Sessions Will Start
//New Session Variable Will Create Here
$schque = "Sample_User";
$_SESSION['user']= $schque;
echo '<a href="next.php">Next Page</a>';
?>[/PHP]

next.php
[PHP]<?php
session_start();//Here You Have to Start the Session
$schque = $_SESSION['user'];//Get the Session Created From Prevous Page to A New Variable
echo $schque;
?>[/PHP]
Mar 2 '07 #4

P: 8
Try This Sample

First.php
[PHP]<?php
session_start();// Sessions Will Start
//New Session Variable Will Create Here
$schque = "Sample_User";
$_SESSION['user']= $schque;
echo '<a href="next.php">Next Page</a>';
?>[/PHP]

next.php
[PHP]<?php
session_start();//Here You Have to Start the Session
$schque = $_SESSION['user'];//Get the Session Created From Prevous Page to A New Variable
echo $schque;
?>[/PHP]
then how do i get $a = $schque so I can use it for

$query="SELECT * FROM user WHERE username='$a'";
Mar 2 '07 #5

ak1dnar
Expert 100+
P: 1,584
Your Question is Not Clear.

From the First page you have to create a Session variable.It may be a User Input something like Login page or etc.

How ever Create the User session variable from the First Page.
Then as i showed to you Get it from the Next Pages.

If you want to PUT that Session varible to SQL Query
Why again using this
[PHP]$a=$_REQUEST['$schque'];[/PHP]

You can directly Pass $schque

to Your SQL Script Like
since you have fetched the user value to that Variable
[PHP]$schque = $_SESSION['user'];
$query="SELECT * FROM user WHERE username='$schque'";[/PHP]

If this is Not Clear POST All Your Coding Here.Becoz I cant Undestand Your Incomplete Question
Mar 2 '07 #6

P: 8
Your Question is Not Clear.

From the First page you have to create a Session variable.It may be a User Input something like Login page or etc.

How ever Create the User session variable from the First Page.
Then as i showed to you Get it from the Next Pages.

If you want to PUT that Session varible to SQL Query
Why again using this
[PHP]$a=$_REQUEST['$schque'];[/PHP]

You can directly Pass $schque

to Your SQL Script Like
since you have fetched the user value to that Variable
[PHP]$schque = $_SESSION['user'];
$query="SELECT * FROM user WHERE username='$schque'";[/PHP]

If this is Not Clear POST All Your Coding Here.Becoz I cant Undestand Your Incomplete Question
Thanks that worked, I was being stupid as per usual, sorry for being confusing.
Mar 5 '07 #7

ak1dnar
Expert 100+
P: 1,584
Thanks that worked, I was being stupid as per usual, sorry for being confusing.
Its a pleasure to here that.You are warmly welcome anytime.
:) Ajaxrand
Mar 6 '07 #8

Post your reply

Sign in to post your reply or Sign up for a free account.