Page 1 of 1
variable passing help!!
Posted: Tue Aug 08, 2006 7:08 am
by just a member
Hi,
i have an html page lets say page.html which contain a form with input field called username and i have two php pages lets say page1.php and page2.php. now the problem is that i need to use the variable username in page1.php and page2.php but how i can do that i know i should use a $_session but i don't know how sorry about my question but i just start learning php and i need it in my project so if any body can help me with a siple example i will be very thankfull
kind regards
Posted: Tue Aug 08, 2006 8:13 am
by JayBird
Have you got any code yet?
Posted: Tue Aug 08, 2006 8:42 am
by php3ch0
HINT:
Code: Select all
session_start();
$_SESSION['username']= ...
Posted: Tue Aug 08, 2006 9:28 am
by just a member
Pimptastic | Please use Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
thank you for response,
yes i have code
the html page called log_in.html and it contain form with username field
Code: Select all
<?php session_start();
$_SESSION['username']='username';
?>
<form method="POST" action="log_in.php" name="myform" onSubmit="return validateform( this.form )" >
<input name="username" size="20" style="border: 1px inset #000000" dir="ltr" maxlength="8">
and i have logged_in.php and there i don't have any proplem the problem is in personal_information.php where i need to use the variable username to specify the retrieving from the database, i use postgresql !
i'm so confused about using $_SESSION i meen i should put session_start(); in every page or what ??
kind regards
Pimptastic | Please use Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Posted: Tue Aug 08, 2006 9:44 am
by php3ch0
Code: Select all
$_SESSION['username']=$_POST['username'];
Posted: Tue Aug 08, 2006 10:38 am
by just a member
Pimptastic | Please use Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
hi again,
sorry for many question but i realy need to understand this.
now in log_in.html i should code with
Code: Select all
<?php session_start();
$_SESSION['username']='$username';
?>
and thin at personal_information.php i should start the code with
Code: Select all
<?php session_start();
$_SESSION['username']=$_POST['username'];
am i right!? if so how i can use the value of username in the SQL query?? should i use it as 'username' or '$username' or what??!
sorry again for my silly questions.
kind regards
Pimptastic | Please use Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Posted: Tue Aug 08, 2006 1:26 pm
by php3ch0
Thats it, your sql query would be like:
SELECT * from table where username = '$username'
Posted: Wed Aug 09, 2006 7:16 am
by just a member
thank u very much ,
but i;m very disappointed because it didn't work the query didn't give me any results i don't know what is the problem but when i try the code with a specific username it give me the results i want so, i think the proplem with passing the variable from the html form!!!???
kind regards
Posted: Wed Aug 09, 2006 7:58 am
by php3ch0
$username = $_SESSION['username'];
before your sql query
Posted: Wed Aug 09, 2006 8:48 am
by just a member
Posted: Wed Aug 09, 2006 8:51 am
by JayBird
Code: Select all
<?php session_start();
$_SESSION['username']='$username';
?>
That is NEVER going to work because variabls inside singles quotes dont get parsed
it needs to be like this
Code: Select all
<?php session_start();
$_SESSION['username']=$username;
?>
Infact, looking at your code, i think what you need is
Code: Select all
<?php session_start();
$_SESSION['username']=$_POST['username'];
?>